#897: Bi-Directional ManyToMany in Admin
-------------------------------+------------------------------------
Reporter: anonymous | Owner: nobody
Type: New feature | Status: new
Component: contrib.admin | Version:
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------+------------------------------------
Comment (by Emmanuel Katchy):
For clarity and to help whoever might take this up in the future:
This is still an issue in Django ''5.2.dev20240621100134''.
Given the following models
{{{
from django.db import models
class Student(models.Model):
name = models.CharField(max_length=50)
age = models.PositiveIntegerField()
def __str__(self) -> str:
return self.name
class Course(models.Model):
name = models.CharField(max_length=20)
students = models.ManyToManyField(
to=Student,
related_name="courses",
related_query_name="course",
)
def __str__(self) -> str:
return self.name
}}}
and the admin.py
{{{
from django.contrib import admin
from django.contrib.admin import ModelAdmin
from core.models import Course, Student
@admin.register(Course)
class CourseAdmin(ModelAdmin): ...
@admin.register(Student)
class StudentAdmin(ModelAdmin):
filter_horizontal = [
"course",
]
}}}
It raises an error
{{{
ERRORS:
<class 'core.admin.StudentAdmin'>: (admin.E020) The value of
'filter_horizontal[0]' must be a many-to-many field.
}}}
This error is raised by
**django.contrib.admin.checks.BaseModelAdminChecks._check_filter_item**.
However, getting the widget to render would require modifying
**ModelAdmin.get_form** as well.
--
Ticket URL: <https://code.djangoproject.com/ticket/897#comment:48>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
--
You received this message because you are subscribed to the Google Groups
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/django-updates/01070190d7ad837b-df123416-d3a9-4483-978a-f0107c1c0708-000000%40eu-central-1.amazonses.com.