开发者

Django Model subclass without changing database name

开发者 https://www.devze.com 2023-01-07 15:09 出处:网络
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 d

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 s开发者_运维技巧uper class to determin the database name, or a way to retrieve the table name and apply it in the model's Meta class.


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

0

精彩评论

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