views:

45

answers:

2

I want to add a column to a database table but I don't want to modify the 3rd party module in case I need/decide to upgrade the module in the future. Is there a way I can add this field within my code so that with new builds I don't have to add the field manually?

+3  A: 

You can use ModelName.add_to_class (or .contribute_to_class), but if you have already run syncdb, then there is no way to automatically have it add the columns you need.

For maintainable code, you will probably want to extend by sub-classing the desired model in your own app, and use something like south to handle the database migrations, or just use a OneToOneField, and have a related model (like UserProfile is to auth.User).

Matthew Schinckel
A: 

Take a look to Django model inheritance and abstract classes http://docs.djangoproject.com/en/dev/topics/db/models/#multi-table-inheritance

cues7a