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



Question:

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.


Solution:1

Field.db_column.


Solution:2

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


Solution:3

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

Note:If u also have question or solution just comment us below or mail us on toontricks1994@gmail.com
Previous
Next Post »