Access Model Field Attributes in Django

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 am trying to get both the value and the detailed field name. How can i do this?

I looked at myModel._meta.fields , but I'm not sure if this is the way to go.

+7
source share
1 answer

Probably like this:

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

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

+8
source

All Articles