1

I working on a project where I need to add two dependant dropdowns for that I tried to use Django-smart-selects but I having an issue. Here's what I did

Here is my models

class District(models.Model):
name = models.CharField(max_length=100, default=None)
created_at = models.DateField(default=django.utils.timezone.now)

class Meta:
    managed = True
    db_table = 'District'

def __str__(self):
    return self.name


class PoliceStation(models.Model):
name = models.CharField(max_length=100, default=None)
district = models.ForeignKey(
    District, on_delete=models.CASCADE, max_length=100)
created_at = models.DateField(default=django.utils.timezone.now)

class Meta:
    managed = True
    db_table = 'PoliceStation'

def __str__(self):
    return self.name

class NewsAndUpdates(models.Model):
title = models.CharField(max_length=250)
description = HTMLField()
category = models.ForeignKey(
    Category, on_delete=models.CASCADE, max_length=100)
district = models.ForeignKey(
    District, on_delete=models.CASCADE)

policeStation = ChainedForeignKey(
    PoliceStation,
    chained_field="district",
    chained_model_field="district",
    show_all=False,
    auto_choose=True,
    on_delete=models.CASCADE)

class Meta:
    managed = True
    db_table = 'NewsAndUpdates'

This is my urls.py

urlpatterns = [
  path('admin/', admin.site.urls),
  path('chaining/', include('smart_selects.urls')),
]

Here is my installed apps

INSTALLED_APPS = [
....
'smart_selects',
]

In setting.py I used this as it was suggested when I was searching about the issue

USE_DJANGO_JQUERY = True

This is my admin.py

class NewsAndUpdatesAdmin(admin.ModelAdmin):
list_display = ('title', 'category', 'created_at',
                'is_published', 'is_draft')

admin.site.register(NewsAndUpdates, NewsAndUpdatesAdmin)

But I am getting issue which is Reverse for 'chained_filter' not found. 'chained_filter' is not a valid view function or pattern name

Screenshot

Using Django version 3.1

3 Answers3

0

The NoReverseMatch error is saying that Django cannot find a matching url pattern for the url you've provided in any of your installed app's urls. The NoReverseMatch exception is raised by django. ... urlresolvers when a matching URL in your URLconf cannot be identified based on the parameters supplied.

Ankit Tiwari
  • 4,438
  • 4
  • 14
  • 41
0

I have got this error when I hadn't registered smart_selects.urls in urls.py.

Rasul
  • 33
  • 4
0

Add to /app/urls.py:

urlpatterns = [
    re_path(r'^chaining/', include('smart_selects.urls'))
]
chococroqueta
  • 694
  • 1
  • 6
  • 18