Suppose I have the following models:

class A(models.Model): name = models.TextField() class B(models.Model): name = models.TextField() a = models.ForeignKey(A) 

Task: There is a form with two fields, the first one displays the list of objects A, the second list of objects B. It is necessary that the field with the list of objects B be filtered according to the selected object A.

Now it is implemented as ajax function on the server that accepts the selected object A, and returns the list belonging to the B + objects and, accordingly, on the client, the js code that sends the selected object and replaces the list with filtered ones.

There are cases when on the form of nested models there are not two, but three, four .. as a result, a lot of “stupid” logic is obtained. Is it possible to do this using django or its additions?

    1 answer 1

    See django-smart-selects , django-chained-selects

    • django-chained-selects what you need, allows you to do everything at the form level, thanks! - thevoid