Answer the question
In order to leave comments, you need to log in
How to make a dependency in django-select2 + django-mptt?
Hello. I can't solve the problem.
I have an mptt model, let's call it - Category
There is an Attribute model in which there is a FK field to Category in which you need to specify only the parent (that is, a category that has subcategories) Category
There is a Product model in which there are fields:
- FK to Category in which you need to specify a child category
- and the field (attributes) is M2M on Attribute
Next, in the form for django-admin, django-select2 is used for all FK and M2M fields.
I need to do this in the Product model:
- so that when you select a Category, the attributes field, which is M2M, depends on the Category and select2 displays only those Attribute that depend on the Category - I know how to do this.
Now I don’t know how to make it so that when a child Category is selected, the parent Category is somehow found from it and substituted into the Attribute search, since in Attribute we can only specify the parent Category. In the dependent_fields widget itself, you cannot specify a field with a prefix (of type category__parent), only the field itself. And before that, it’s also impossible to pull out the field and insert it, or I don’t know, and whether it will give me something. The documentation doesn't say anything about prefixes
Help...
Answer the question
In order to leave comments, you need to log in
You can’t figure it out without 100 grams in your description of the problem, I dare to suggest that limit_choices_to can help
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question