views:

22

answers:

1

I am making a Django Model decorator which takes a Django model and gives it a few extra methods.

Django creates the database name for this Model using: '%s_%s' % (app_name, class_name). When you decorate the Model the table name is suddenly derived from the app name and class name of the decorator rather than the original class (which is pythonically correct).

However I would like to maintain the original table name of the Model, is there a way to tell Django to use the super class to determin the database name, or a way to retrieve the table name and apply it in the model's Meta class.

+1  A: 

You can override this in class Meta:

http://docs.djangoproject.com/en/1.1/ref/models/options/#django.db.models.Options.db_table

To make a new model using the specs of the superclass, look into proxy = True

http://docs.djangoproject.com/en/1.1/topics/db/models/#id8

eruciform
Yup, but override it with what. I could get the name and app name of the super class but then I am assuming that it hasn't already been overridden. If there is a way to get what the table name would be for the super class and set `db_table` to that, it could work.
Marcus Whybrow
updated. check out proxy objects, see if that suffices :-)
eruciform
Thanks eruciform, I just spotted that too. `proxy = True` does the trick cheers!
Marcus Whybrow