Django dynamic combobox

0

The query I have is the following:

Example of the model

class Marca(models.Model):

    marca = models.CharField(max_length=30)    

class Modelo(models.Model):

    modelo = models.CharField(max_length=30)    
    marca = models.models.ForeignKey()

Example of the form

class miForm(forms.Form):

    marca = forms.ModelChoiceField(queryset=Marca.objects.all())
    modelo = forms.ModelChoiceField(queryset=Modelo.objects.all())

When showing them in my template both are loaded with all the records, but I need to select a brand of the combobox to show me the models associated with that brand.

I imagine that it could be filtered from the form by the selected brand, but that is what I do not know how to do, is it possible to pass the value that the user selected to the form to make the query with that filter?.

The other thing that occurs to me is to initialize it empty and based on the brand selection in the view load the models of that brand and pass it to the template and there just load.

Thank you very much for your time and help.

    
asked by rodrigo_uy 13.05.2017 в 01:18
source

0 answers