Say I have a Django class something like this:
class Person(models.Model):
name = models.CharField(max_length=50)
# ...
How can I programatically obtain the max_length
value for the name
field?
Say I have a Django class something like this:
class Person(models.Model):
name = models.CharField(max_length=50)
# ...
How can I programatically obtain the max_length
value for the name
field?
Person._meta.get_field('name').max_length
will give you this value. But having to use _meta
suggests this is something you shouldn't do in normal usage.
Edit: as Carl pointed out, this naming is misleading and it does seem quite acceptable to use it: http://www.b-list.org/weblog/2007/nov/04/working-models/