2

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?

Community
  • 1
  • 1
stillLearning
  • 723
  • 6
  • 9

2 Answers2

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