Question

I have Django models as follows:

class Subject(models.Model):
    name = models.CharField(max_length=35, unique=True)
class Book(models.Model):
    title = models.CharField(max_length=400)    
    subject = models.ManyToManyField(Subject, related_name='books', blank=True, verbose_name="Subject")

There are many Subjects - around 100.

When editing a Book record on the Django admin, it is very difficult to see which subjects are present on a particular book.

The Django admin offers a multi-select list, which is great, but to see for a book, you have to scroll through the entire select list.

It would be much better if either:

  1. I could offer a read-only list of the subjects above the multi-select list, or
  2. the multi-select list began with the selected subjects, then had an entry like '----', then continued with the other subjects.

Does anyone have any idea how I could implement either of the above in Django, to improve the usability of ManyToManyFields in the Django admin?

Thanks!

Was it helpful?

Solution

Use filter_horizontal (or filter_vertical).

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top