11

I have a model in Django 1.2.4:

class MyModel():
    foo = IntegerField(verbose_name="bar")

    def printFoo(self):
        print("Value of %s is %d" % (foo.verbose_name, foo))

I'm trying to get both the value and verbose name of a field. How can I do this?

I've looked at myModel._meta.fields, but I'm not sure if that's the way to go.

Nick Heiner
  • 114,397
  • 181
  • 465
  • 693

1 Answers1

14

Probably like this:

MyModel._meta.get_field('foo').verbose_name

See How can I programmatically obtain the max_length of a Django model field? for a very similar question.

Community
  • 1
  • 1
Ben James
  • 114,847
  • 26
  • 189
  • 155