A
A
Andrey2016-04-26 19:48:02
Django
Andrey, 2016-04-26 19:48:02

How to make additional fields based on the value of another field?

Hello!
There is a form for creating a request for the search for a car part, it is necessary that additional fields be loaded when choosing a part. Each spare part may have its own specific parameters/options!
d76cf85b6786452e86df73acebf2d987.jpg
For example, for the engine, you no longer need to specify the position, but you need the parameters mileage to and with mounted yes / no , etc.
The models are simple:
Part
name
Query
part = Part #fk
comment
...
It turns out that you can add the model
PartOption
part = Part #fk
label #option name
type #field type char/select/int etc.
choies #options for select
Then, when choosing a spare part, pull up additional fields with ajax.
In general, tell me how to implement it correctly, maybe there are already some ready-made batteries for Django, maybe you had similar tasks?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
Alexey Sergeev, 2016-04-27
@SergeevAI

We send the selected parameters via ajax via onchange, process them in if request.POST.is_ajax(), return the required form with json and add forms via JS. Something like this.

K
Kirill, 2016-04-28
@Air_Walker

I had something similar in my project. We decided to show additional js fields custom when selecting the desired position. There was also a custom clean on the backend. They couldn’t find a better solution, and there was no time to sweat a lot with Ajax and the frontend.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question