djangodjango-ajax-selectsdjango-smart-selects

I use two interconnected ChainedForeignKey fields, but they don't. why?


my problem: I have three models. il (province), ilce (district) and mahalle (neighborhood). I filter with smart-select. works smoothly in the entry of information. When I looked at the database, I saw that mahalle (neighborhood) data was recorded. but the mahalle (neighborhood) widget sounds empty.

my models:

class il(models.Model):
    adi = models.CharField(max_length=20)

class ilce(models.Model):
    ill = models.ForeignKey(il, on_delete=models.CASCADE)
    adi = models.CharField(max_length=35)

class mahalle(models.Model):
    ilcee = models.ForeignKey(ilce, on_delete=models.CASCADE)
    adi = models.CharField(max_length=50)


class User(AbstractUser):
    username = None
    email = models.EmailField(_('email address'), unique=True)
    .......
    kurum_il = models.ForeignKey('il', on_delete=models.SET_NULL, null=True, blank=False)
    kurum_ilce = ChainedForeignKey('ilce', chained_field="kurum_il", chained_model_field="ill", show_all=False, sort=False, null=True, blank=False)
    kurum_mahalle = ChainedForeignKey('mahalle', chained_field="kurum_ilce", chained_model_field='ilcee', show_all=False, sort=False, null=True, blank=False)

Does not appear on the Admin page even though I enter and save neighborhood information related screenshot


Solution

  • Django-smart-selects looks long unmaintained with last release in 2018.

    However there are few issues raised / discussed for it that may relate to your question, one of them #237. As a solution it has this Pull Request with little change to .js file (actually it just comments out one line).

    As it is not yet included in official release, you can apply these changes manually and provide new .js file to override package one: