1

Hi I am doing a project in Django 1.10. For this project I am using django-smart-select for chaining input in the admin panel. It works fine. But for many to many fields chaining if I use filter_horizontal/filter_vertical then the chaining does not work any more. There was no solution in there github page. How can i solve this problem? Is there another app like this?

Al-Alamin
  • 1,438
  • 2
  • 15
  • 34

1 Answers1

0

I have the same problem and I solved it in this fork from the library: https://github.com/jorgecorrea/django-smart-selects As you can see in my README version, this is the way to use in horizontal mode with mi fork: models.py

from smart_selects.db_fields import ChainedManyToManyField

class Publication(models.Model):
    name = models.CharField(max_length=255)

class Writer(models.Model):
        name = models.CharField(max_length=255)
        publications = models.ManyToManyField('Publication', 
                                              blank=True,
                                              null=True)

class Book(models.Model):
        publication = models.ForeignKey(Publication)
        writer = ChainedManyToManyField(
            Writer,
            horizontal=True,
            verbose_name='writer',
            chained_field="publication",
            chained_model_field="publications",
        )
        name = models.CharField(max_length=255)

with this little change you can use django horizontal mode view, but do not add the field to admin filter_horizontal this change is not needed: admin.py

@admin.register(Book)
class BookAdmin(admin.ModelAdmin):
    filter_horizontal = ('writer',)
   # don't do that because you will be changing the widget.