0

I want to update a form based on user selection of one field. Here is my models.py

models.py

class A(Model):
    text = CharField()

class B(Model):
    a = ForeignKeyField(A)

class C(Model):
    a = ForeignKeyField (A)
    b = ForeignKeyField(B)

Assuming we use ModelChoiceField in forms.py. Now if a user is adding a C object, and he selects an A object, I want to populate B field with queryset=a.b_set. Is there any way to do this in django? Or if I have to use Javascript, is there a best practice as to how to integrate this with django? Thanks

Asym
  • 1,836
  • 3
  • 21
  • 36

1 Answers1

0

I ended up using https://github.com/PragmaticMates/django-clever-selects .

this library uses ajax under the hood and allows to add chained select widgets easily. I even customized it to work with mdl.

Asym
  • 1,836
  • 3
  • 21
  • 36