jazzband / django-smart-selects

chained and grouped selects for django forms
https://django-smart-selects.readthedocs.io/
BSD 3-Clause "New" or "Revised" License
1.12k stars 352 forks source link

Empty dropdown for chained field #357

Closed lguariento closed 5 months ago

lguariento commented 5 months ago

Put an x in the bracket when you have completed each task, like this: [x]

Steps to reproduce

This my my models.py:

from smart_selects.db_fields import ChainedForeignKey

class Funder(models.Model):
    name = models.CharField(max_length=200)
    scheme = models.ManyToManyField('Scheme', blank=True, related_name='funders')

class Scheme(models.Model):
    name = models.CharField(max_length=200)

class Project(models.Model):
    title = models.CharField(max_length=200)
    funder = models.ForeignKey(Funder, on_delete=models.PROTECT, null=True, blank=True)
    scheme = ChainedForeignKey(
        Scheme,
        chained_field="funder",
        chained_model_field="funder",
        show_all=False,
        auto_choose=True,
        sort=True, null=True, blank=True)

In my Django admin backend, go to any project, existing or new. Select a funder from the funder dropdown.

Actual behavior

There is no scheme in the scheme dropdown, although that specif funder does indeed contain one or more scheme.

Expected behavior

The scheme dropdown should show all the schemes linked to that specific funder.

This is with smart_selects v. 1.7.1 (installed via pip install git+https://github.com/jazzband/django-smart-selects.git) and Django 5.0.4.

It used to work with previous versions.

lguariento commented 5 months ago

Apologies, I had to set chained_model_field to funders.