#15221: Show field's verbose name instead of related model name for M2M
filterspecs
----------------------------------+-----------------------------------------
Reporter: julien | Owner: nobody
Status: new | Milestone: 1.3
Component: django.contrib.admin | Version: 1.2
Keywords: | Triage Stage: Unreviewed
Has patch: 1 |
----------------------------------+-----------------------------------------
Consider the following example:
Model:
{{{
#!python
from django.db import models
from django.contrib.auth.models import User
class Book(models.Model):
title = models.CharField(max_length=25)
year = models.PositiveIntegerField(null=True, blank=True)
author = models.ForeignKey(User, related_name='books_authored',
blank=True, null=True)
contributors = models.ManyToManyField(User,
related_name='books_contributed', blank=True, null=True)
}}}
Admin:
{{{
#!python
from django.contrib import admin
from .models import Book
class BookAdmin(admin.ModelAdmin):
list_display = ('title', 'year', 'author')
list_filter = ('year', 'author', 'contributors')
admin.site.register(Book, BookAdmin)
}}}
Presumably since #3400 was fixed, M2M filterspecs are using the related
model's name as title. This leads the example above to display "By user"
instead of "By contributors". This is a bit silly in itself but it could
be even more problematic if multiple M2M filters to User were specified at
the same time.
I've discussed this with DrMeers (who wrote the patch for #3400). The
patch I'm attaching seems to fix the issue but we might have to
investigate a bit more to see if there are cases where it wouldn't make
sense to show the field's verbose name for a M2M.
The patch doesn't contain tests yet. I'm waiting to get feedback on the
latest patch I've posted in #8528 which introduces a new module for
filterspecs' tests. If #8529 gets checked in then writing tests for this
patch will be trivial.
--
Ticket URL: <http://code.djangoproject.com/ticket/15221>
Django <http://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 post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/django-updates?hl=en.