Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

236
Views
Django: limit_choices_to with with a "through" intermediate table

https://docs.djangoproject.com/en/1.10/ref/models/fields/:
"limit_choices_to has no effect when used on a ManyToManyField with a custom intermediate table specified using the through parameter."

Why?! And what to do if I need both through and limit_choices_to?

Should I fall back from ModelForm to simple Form in this situation and do it all manually? Or is there a way to do it with ModelForm?

about 4 years ago · Santiago Trujillo
1 answers
Answer question

0

I tested limit_choices_to with a through ManyToManyField. And surprisingly it works, despite the docs say it doesn't.

Still, if it's not working for you, you can set a custom queryset for the ManyToMany field in your ModelForm.

# models
class YourModel(models.Model):
    some_attr = models.BooleanField()

class MyModel(models.Model):
    my_field = models.ManyToManyField(YourModel, through=...)


# forms
class MyModelForm(forms.ModelForm):
    ...
    my_field = forms.ModelMultipleChoiceField(queryset=YourModel.objects.filter(some_attr=True)) 
about 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!