开发者

Accessing 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'm trying to get both the valu开发者_StackOverflow社区e 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.


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜