Opened 14 years ago
Last modified 13 years ago
#14529 closed
Save messages for proxy models show a crazy verbose_name — at Version 4
Reported by: | Owned by: | nobody | |
---|---|---|---|
Component: | contrib.admin | Version: | dev |
Severity: | Keywords: | ||
Cc: | Triage Stage: | Accepted | |
Has patch: | yes | Needs documentation: | no |
Needs tests: | yes | Patch needs improvement: | no |
Easy pickings: | no | UI/UX: | no |
Description (last modified by )
Steps to reproduce:
- In a ModelAdmin, provide a custom queryset method that adds .only().
- Save a model in the admin.
Expected results:
A
The model name "whatever" was saved successfully.
message.
Actual results:
A
The model_name_deferred__all_the_fields_you_did_not_load "whatever" was saved successfully.
message.
Change History (6)
by , 14 years ago
Attachment: | 14529-save-messages-for-proxy-models.diff added |
---|
comment:1 by , 14 years ago
Needs tests: | set |
---|
comment:2 by , 14 years ago
milestone: | → 1.3 |
---|---|
Patch needs improvement: | set |
Triage Stage: | Unreviewed → Accepted |
Version: | 1.2 → SVN |
Okay, I can confirm this happens in 1.2 and in trunk.
I've applied the patch but it solves this partially. Also, I'm not sure that's the best approach.
When you don't define a __unicode__()
it shows "whatever"_Deferred_"fields" object
in the changelist's list always.
comment:3 by , 14 years ago
Here's a simple test case:
Model:
from django.db import models class Book(models.Model): name = models.CharField(max_length=100) author = models.CharField(max_length=100, blank=True)
Admin:
from django.contrib import admin from .models import Book class BookAdmin(admin.ModelAdmin): list_display = ('name',) def queryset(self, request): return super(BookAdmin, self).queryset(request).only('name') admin.site.register(Book, BookAdmin)
Narrowing down the issue with print
statements in django.contrib.admin.options
:
def change_view(self, request, object_id, extra_context=None): ... print "Before:" + force_unicode(opts.verbose_name) return self.response_change(request, new_object) ... def response_change(self, request, obj): """ Determines the HttpResponse for the change_view stage. """ opts = obj._meta print "After:" + force_unicode(opts.verbose_name) ...
This results in:
Before:book After:book_ deferred_author
So apparently the issue occurs when the meta options are reloaded in response_change()
with opts = obj._meta.
Note that the issue only arises with the change view. With the add view, the correct verbose names are displayed.
A trivial patch to fix this issue