Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 479861
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T00:50:04+00:00 2026-05-13T00:50:04+00:00

I have a model not unlike the following: class Bike(models.Model): made_at = models.ForeignKey(Factory) added_on

  • 0

I have a model not unlike the following:

class Bike(models.Model):
    made_at = models.ForeignKey(Factory)
    added_on = models.DateField(auto_add_now=True)

All users may work at a number of factories and therefore their user profiles all have a ManyToManyField to Factory.

Now I want to construct a ModelForm for Bike but I want the made_at list to consist of only factories at which the current user works. The idea is that users should be able to add bikes that they’ve assembled and enter which of the factories the bike was made at.

How do I do that?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-13T00:50:05+00:00Added an answer on May 13, 2026 at 12:50 am

    You question might be a dupe of this.

    S. Lott‘s answer there is the ticket to solve your problem.
    He answered:

    ForeignKey is represented by django.forms.ModelChoiceField, which is a ChoiceField whose choices are a model QuerySet. See the reference for ModelChoiceField.

    So, provide a QuerySet to the field’s queryset attribute. Depends on how your form is built. If you build an explicit form, you’ll have fields named directly.

    form.rate.queryset = Rate.objects.filter(company_id=the_company.id)
    If you take the default ModelForm object, form.fields["rate"].queryset = ...

    This is done explicitly in the view. No hacking around.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Suppose I have this model (not real code): class Message(models.Model): content = models.CharField(...) mentions
I have model: [XmlRoot(ElementName = event, IsNullable=true)] public class Event { public int id
I have model created field configurated as follows: created = models.DateTimeField(auto_now_add=True) In JSON fixtures
I have a model, view and controller not interacting correctly, and I do not
I have a view model with a couple of properties that are not displaying
I have a simple Poco-Model using abstract classes, and it seems not to work
I have a two models that are similar, but not exactly the same. Here's
I have a bunch of models that may or may not have a property
I have model public class UploadOptionModel { public UploadOptionModel() { OutputFormat = outputFormatList.Select(i =>
I need to have a model which will behave like a embedded and not-embedded.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.