Opened 14 years ago

Closed 14 years ago

Last modified 13 years ago

#14529 closed (fixed)

Save messages for proxy models show a crazy verbose_name

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.

Attachments (2)

14529-save-messages-for-proxy-models.diff (597 bytes ) - added by rlaager@… 14 years ago.
A trivial patch to fix this issue
14529.1.diff (1.5 KB ) - added by Ramiro Morales 14 years ago.
Another similar patch but with reduced impact.

Download all attachments as: .zip

Change History (10)

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.

comment:5 by Ramiro Morales, 14 years ago

Patch needs improvement: unset

The new patch is similar to the one uploaded by rlaager but it only uses the model verbose name of the proxied model when the model associated with the ModelAdmin is an synthetic proxy model originated from the use of .only() or .defer().

It still needs tests.

comment:6 by Ramiro Morales, 14 years ago

Resolution: fixed
Status: newclosed

In [15596]:

Fixed #14529 -- Fixed representation of model names in admin messages after model object changes when the ModelAdmin queryset() uses defer() or only(). Thanks rlaager for report and initial patch, to rasca an julien for help in tracking the problem.

comment:7 by Ramiro Morales, 14 years ago

In [15597]:

[1.2.X] Fixed #14529 -- Fixed representation of model names in admin messages after model object changes when the ModelAdmin queryset() uses defer() or only(). Thanks rlaager for report and initial patch, to rasca an julien for help in tracking the problem.

Backport of [15596] from trunk.

comment:8 by Jacob, 13 years ago

milestone: 1.3

Milestone 1.3 deleted

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