I assume you're using Django smart selects since you seem to be using chained foreign key. Here's the documentation on how to get this to work inside your own templates:
https://django-smart-selects.readthedocs.io/en/latest/usage.html#usage-in-templates On October 11, 2021 8:36:21 AM CDT, maryam yousaf <maryamyousaf32...@gmail.com> wrote: >Hello, > >I have one model which is campaign tracking. In that mode, I have two Fk's >country and city. Cities are linked with country as I am using chained >filtering so, it is working fine on model level where user has to give >inputs but I also have to provide two filters on web interface Country and >City. In filters, I want to have this functionality that when user choose >any specific country from the drop down filter then in Cities filter, only >specific cities who belongs to the selected country should appear in drop >down but currently, I am getting all the cities. Any help is appreciated. > >See the code below. > >*models.py:* >class CampaignTracking(models.Model): >campaign_tracking_id = models.AutoField(primary_key=True) >country = models.ForeignKey(Country, on_delete=models.PROTECT) >city = ChainedForeignKey( >City, >chained_field='country', >chained_model_field='country', >show_all=False, >auto_choose=False, >sort=True, >null=True, >blank=True, >on_delete=models.PROTECT >) >campaign_name = models.ForeignKey(Campaign, on_delete=models.CASCADE) >campaign_category = models.ForeignKey(CampaignCategory, >on_delete=models.CASCADE) >start_date = models.DateField() >end_date = models.DateField() >start_date_pre_campaign_period = models.DateField() >end_date_pre_campaign_period = models.DateField() >start_date_post_campaign_period = models.DateField() >end_date_post_campaign_period = models.DateField() >history = HistoricalRecords() > > >*Admin.py:* >class CountryFilter(AutocompleteFilter): >title = 'Country' >field_name = 'country' > > >class CityFilter(AutocompleteFilter): >title = 'City' >field_name = 'city' > >class CampaignTrackingAdmin(SimpleHistoryAdmin): >list_display = ('country', >'city', >'campaign_name', >'campaign_category', >'start_date', >'end_date', >'start_date_pre_campaign_period', >'end_date_pre_campaign_period', >'start_date_post_campaign_period', >'end_date_post_campaign_period', >) >list_filter = (CountryFilter, >CityFilter, >) > >Current filter in django Web Interface: > >-- >You received this message because you are subscribed to the Google Groups >"Django users" group. >To unsubscribe from this group and stop receiving emails from it, send an >email to django-users+unsubscr...@googlegroups.com. >To view this discussion on the web visit >https://groups.google.com/d/msgid/django-users/bc67100a-bcdc-4b4c-a8b4-630d2a859aa2n%40googlegroups.com. -- You received this message because you are subscribed to the Google Groups "Django users" group. To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/DDFCA28B-4B81-4F99-B11C-5DAE25FA1419%40fattuba.com.