Opened 7 years ago

Closed 7 years ago

Last modified 3 years ago

#8024 closed (fixed)

Changeset 8132 breaks labels on ForeignKey Fields

Reported by: arne Owned by: mtredinnick
Component: Uncategorized Version: master
Severity: Keywords: label, verbose_name, model
Cc: Triage Stage: Accepted
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: UI/UX:

Description

The change in r8132 leads to empty labels in the admin change-forms if the ForeignKey Fields don't have an verbose_name parameter set.

To reproduce just create two models:

class ModelA(models.Model):
    title = models.CharField(max_length=20)

class ModelB(models.Model):
    foo = models.ForeignKey(ModelA)

and register the models with the admin app

class ModelAadmin(admin.ModelAdmin):
    pass

class ModelBadmin(admin.ModelAdmin):
    pass

admin.site.register(ModelA, ModelAadmin)
admin.site.register(ModelB, ModelBadmin)

In the Admin Change-Form of ModelB an empty label is displayed on the ForeignKeyField to ModelA (only a ":" displayed, expected output would be "Model a:")

The following patch fixes the problem, but I'm not sure if it breaks the problem which should be fixed by r8132 which was reported in #8011

--- db/models/fields/related.py	(revision 8137)
+++ db/models/fields/related.py	(working copy)
@@ -117,7 +117,7 @@
 
     def set_attributes_from_rel(self):
         self.name = self.name or (self.rel.to._meta.object_name.lower() + '_' + self.rel.to._meta.pk.name)
-        if self.verbose_name is None:
+        if not self.verbose_name:
             self.verbose_name = self.rel.to._meta.verbose_name
         self.rel.field_name = self.rel.field_name or self.rel.to._meta.pk.name

Change History (4)

comment:1 Changed 7 years ago by Alex

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

This is causing errors all over, see the buildbot.

comment:2 Changed 7 years ago by mtredinnick

  • Owner changed from nobody to mtredinnick

comment:3 Changed 7 years ago by mtredinnick

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

Jacob beat me to it (thankfully). Fixed in [8138], by the looks of it.

comment:4 Changed 3 years ago by jacob

  • milestone 1.0 beta deleted

Milestone 1.0 beta deleted

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