I have a model which I am manipulating through the Django manager.
The model and "its business logic" ask me to establish a specific behavior regarding its form to enter data. What I need to do is the following:
I have the following fields:
What I want to do is that when I select a name in the field Name
, according to the selected value, certain information is displayed (which will also be selected) in the fields Type
,Freedom Degrees
It is something similar to how when one in the registration forms, selects a country and according to that country, the departments/states/provinces appear and according to the selected ones the cities or municipalities appear.
I want to do this for the administration module that Django provides me, and I would also do it in my application itself. I know there are some things to customize the admin interface or working with ModelAdmin.form all to add behaviors
I wanted to share this concern, in case someone has done things like that and if I'm on the right track.
The Django Smart Select package does all the magic you're looking for.
The example is of countries, exactly:
The package requires you to use a custom field type, which makes the package work:
The property
chained_field
indicates which is the binding field in the current model and whichchained_model_field
is the field in the other model.Just follow the installation instructions.
smart_selects
to yourINSTALLED_APPS
.Create the routes in
urls.py
forsmart_selects
chained Select controls to work, for example:It's more complicated with Many to Many fields , but the basic operation is this.