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: rlaager@… 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 Ramiro Morales)

Steps to reproduce:

  1. In a ModelAdmin, provide a custom queryset method that adds .only().
  2. 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 rlaager@…, 14 years ago

A trivial patch to fix this issue

comment:1 by Alex Gaynor, 14 years ago

Needs tests: set

comment:2 by rasca, 14 years ago

milestone: 1.3
Patch needs improvement: set
Triage Stage: UnreviewedAccepted
Version: 1.2SVN

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 Julien Phalip, 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.

comment:4 by Ramiro Morales, 14 years ago

Description: modified (diff)

(reformatted description)

by Ramiro Morales, 14 years ago

Attachment: 14529.1.diff added

Another similar patch but with reduced impact.

Note: See TracTickets for help on using tickets.
Back to Top