Wednesday, November 18, 2020

Using smart_selects in the admin for a ChainedManyToMany?

Looking for some help, if possible

Working Django with 1.11.x and Django smart_selects 1.5.x

from smart_selects.db_fields import ChainedManyToManyField

class Project(Model):
    """Project is a holder for a group of activities carried out as sub-projects.
    """
    id = AutoField(primary_key=True)
    name = CharField(unique=True)
    description = CharField()


class Milestone(Model):
    """Milestone is a time-based goal for a Project.
    """
    id = AutoField(primary_key=True)
    project = ForeignKey(Project)
    description = TextField()
    planned_year = PositiveIntegerField()
    planned_quarter()
   
   
class SubProject(Model):
    """SubProject is an activity carried out as part of a single Project.
    """
    id = AutoField(primary_key=True)
    project = ForeignKey(Project)
    code = CharField(unique=True)
    milestones = ChainedManyToManyField(
        Milestone,
        blank=True,
        horizontal=True,
        chained_field="project",
        chained_model_field="milestones")


However, the admin form for SubProject simply shows the usual admin multi-select box (i.e. just a long list of unfiltered milestones).

What needs to change in the above code to create a working smart_selects version?

Thanks
Derek

--
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+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/CAF1Wu3OK%2BgjaScANCO%3DxC4xi%2BT-e9iaaZqfKtzPpz7jhy6Ai6Q%40mail.gmail.com.

No comments:

Post a Comment