I'm looking to add a human-readable name to a manytomanyfield that will be displayed in a modelform. I've already been here: django display content of a manytomanyfield and that solution doesn't work for modelfields, unless I've misunderstood. I'm sure there's a way to do it, I just haven't been able to figure it out. Does anyone know?
Asked
Active
Viewed 3,872 times
2
-
Do you mean displaying many2many items in ChangeList admin view? – San4ez Mar 27 '12 at 06:20
2 Answers
2
Do you mean a verbose_name field attribute?
foo = models.ManyToManyField("app.Model", ..., verbose_name="bar")

Timmy O'Mahony
- 53,000
- 18
- 155
- 177
1
You can try it this way:
class A(models.Model):
foo = models.CharField("Foo", max_length = 20)
class Meta:
verbose_name = "Human-readable"
verbose_name_plural = "Human-readable"
class B(models.Model):
bars = models.ManyToManyField(A, related_name='if_you_need')
Your bars field should display as "Human-readable".

vutran
- 2,145
- 21
- 34