Responsive Ad Area

Share This Post

test

Django chain filtering results based on selected manytomany fields

I have the following models:

class Country(models.Model):
    name = models.CharField(max_length=50)

class State(models.Model):
    country = models.ForeignKey(Country, on_delete=models.CASCADE)
    name =  models.CharField(max_length=50, null=False, blank=False)

class Species(models.Model):
    name = models.CharField(max_length=50, null=False, blank=False)
    country =models.ManyToManyField(Country)
    state =models.ManyToManyField(State)

Let say I added multiple countries into the a form or admin field. Is there a way to filter the results from the state field based on what I have selected in the country field?

The closest thing I can find that does something similar is django-smart-select but it does not work for my case.


Django chain filtering results based on selected manytomany fields
Django chain filtering results based on selected manytomany fields
test
{$excerpt:n}

Share This Post

Leave a Reply

Your email address will not be Publishedd. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>