#8024 closed (fixed)
Changeset 8132 breaks labels on ForeignKey Fields
| Reported by: | arne | Owned by: | Malcolm Tredinnick |
|---|---|---|---|
| Component: | Uncategorized | Version: | dev |
| 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: | no | UI/UX: | no |
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 by , 17 years ago
| milestone: | → 1.0 beta |
|---|---|
| Triage Stage: | Unreviewed → Accepted |
comment:2 by , 17 years ago
| Owner: | changed from to |
|---|
comment:3 by , 17 years ago
| Resolution: | → fixed |
|---|---|
| Status: | new → closed |
Jacob beat me to it (thankfully). Fixed in [8138], by the looks of it.
This is causing errors all over, see the buildbot.