views:

18

answers:

3

I have a (pre-existing) table witha column 'foo'. I want the model to have a property '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.

+4  A: 

Field.db_column.

Daniel Roseman
Yes, that's exactly right - don't know how I didn't come across the http://docs.djangoproject.com/en/dev/ref/models/fields/ field manual page before.
chrisdew
A: 
class Book(models.Model):
    bar = models.CharField(max_length=255, db_column='foo')

    class Meta:
        db_table = u'actual_table_name'
moskrc