开发者

How do you override the automatically generated fieldnames in a Django model?

I have a (pre-existing) table witha column 'foo'. I want the model to have a prop开发者_StackOverflowerty 'bar' which maps to foo.

I already use

class Meta:
    db_table = u'actual_table_name'

to remap classes/tables from the default table name. Is there a similar way to do this for properties/fields?

Thanks,

Chris.

P.S. This seems like a very simple question, I'm probably just blind to that section of the documentation.


Field.db_column.


You can also give this a try: http://docs.djangoproject.com/en/dev/howto/legacy-databases/#auto-generate-the-models


class Book(models.Model):
    bar = models.CharField(max_length=255, db_column='foo')

    class Meta:
        db_table = u'actual_table_name'
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜