Code

Opened 3 years ago

Closed 3 years ago

#15669 closed New feature (fixed)

Include app label in admin validation messages

Reported by: lamby Owned by: gandalfar
Component: contrib.admin Version: master
Severity: Normal Keywords:
Cc: Triage Stage: Ready for checkin
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: yes

Description

It is possible to have duplicate model names across your project (which is a good thing). However, it currently results in some ambiguous error messages when validating admin classes.

For example:

'MembershipAdmin.raw_id_fields' refers to field 'user_id' that is missing from model 'Membership'.

... does that refer to my Membership class in my "foo" app or my "bar" app?

The attached patch includes the app label in the error messages. For example:

'MembershipAdmin.raw_id_fields' refers to field 'user_id' that is missing from model 'bar.Membership'.

Attachments (3)

01.diff (2.7 KB) - added by lamby 3 years ago.
ticket15669.diff (4.0 KB) - added by Jure Cuhalev <gandalf@…> 3 years ago.
Updated patch with tests
ticket15669_2.diff (8.9 KB) - added by Jure Cuhalev <gandalf@…> 3 years ago.
Updated patch so that modeladmin tests also pass. I also tried approach suggested by Alex and abandoned it because unicode() repr of model lowercases the model, making it harder to grep for errors.

Download all attachments as: .zip

Change History (12)

Changed 3 years ago by lamby

comment:1 Changed 3 years ago by julien

  • Needs documentation unset
  • Needs tests set
  • Patch needs improvement unset
  • Triage Stage changed from Unreviewed to Accepted

Could you provide some tests for this?

comment:2 Changed 3 years ago by lukeplant

  • Type set to New feature

comment:3 Changed 3 years ago by lukeplant

  • Severity set to Normal

comment:4 Changed 3 years ago by julien

  • UI/UX set

comment:5 Changed 3 years ago by Jure Cuhalev <gandalf@…>

  • Easy pickings unset
  • Owner changed from nobody to anonymous
  • Status changed from new to assigned

comment:6 Changed 3 years ago by Jure Cuhalev <gandalf@…>

  • Owner changed from anonymous to gandalfar
  • Status changed from assigned to new

Changed 3 years ago by Jure Cuhalev <gandalf@…>

Updated patch with tests

comment:7 Changed 3 years ago by klette

  • Needs tests unset
  • Triage Stage changed from Accepted to Ready for checkin

comment:8 Changed 3 years ago by Alex

You can simplify to unicode(model._meta) which makes this a bit shorter.

Changed 3 years ago by Jure Cuhalev <gandalf@…>

Updated patch so that modeladmin tests also pass. I also tried approach suggested by Alex and abandoned it because unicode() repr of model lowercases the model, making it harder to grep for errors.

comment:9 Changed 3 years ago by jezdez

  • Resolution set to fixed
  • Status changed from new to closed

In [16462]:

Fixed #15669 -- Included app label in admin validation messages. Thanks, lamby and Jure Cuhalev.

Add Comment

Modify Ticket

Change Properties
<Author field>
Action
as closed
as The resolution will be set. Next status will be 'closed'
The resolution will be deleted. Next status will be 'new'
Author


E-mail address and user name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.