Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

235
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda