Tutorial :Django Model subclass without changing database name



Question:

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.


Solution:1

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


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