Django filter_horizontal pre-selected items

25 Views Asked by At

I want see in django admin filter_horizontal not all my tags, but only tags of one selected group.

Example: My tags: Group Fruits: Apples, Plums, Appricots.. Group Flowers: Roses, Tulips, Asters..

I want to be able select anywhere in admin one plants group (for example "Fruits") and see in filter_horizontal tags "Apples, Plums, Appricots.." , but not "Roses.." My models:

class PlantsGroups(TitleRequiredModel):
    is_active = models.BooleanField(default=True)
    ...

    def __str__(self):
        return self.title

class PlantsTags(TitleRequiredModel):
    is_active = models.BooleanField(default=True)
    ...
    plants_group = models.ForeignKey(PlantsGroups, on_delete=models.CASCADE) 

    def __str__(self):
        return self.title

class PlantsTags(TitleRequiredModel):
    is_active = models.BooleanField(default=True)
    ...
    plants_tags = models.ManyToManyField('PlantsTags', blank=True, related_name="blabla", verbose_name='blablabla')

    def __str__(self):
        return self.title

Thanks!

I am novice to django, please help me :)

0

There are 0 best solutions below