django oscar abstract models customization

1.7k Views Asked by At

I want to override django-oscar address application. What I need is to delete some AbstractAddress attributes (apps.address.abstact_models). According to this docs the process is following - create local app with the same name and do my magic in models module. Dont forget to import * from default abstract_models in the end of the file. Then add this app into installed_apps and finally schemamigration --auto and migrate.

But django didnt pick up changes. Moreover, any attempt to override AbstractAddress class methods are ignored. Why? Is there anything special about abstract_models?

2

There are 2 best solutions below

0
On

The reason usually is your customized model is picked (imported) after the original one of Oscar. Be sure that the application is placed above Oscar's apps.

If not, there is a good tip inside Django Oscar document: http://django-oscar.readthedocs.org/en/latest/topics/customisation.html

Model customisations are not picked up

It’s a common problem that you’re trying to customise one of Oscar’s models, but your new fields don’t seem to get picked up. That is usually caused by Oscar’s models being imported before your customised ones. Django’s model registration disregards all further model declarations.

In your overriding models.py, ensure that you import Oscar’s models after your custom ones have been defined. If that doesn’t help, you have an import from oscar.apps.*.models somewhere that is being executed before your models are parsed. One trick for finding that import: put assert False in the relevant Oscar’s models.py, and the stack trace will show you the importing module.

If other modules need to import your models, then import from your local module, not from Oscar directly.

1
On

The abstract model classes are not meant to be overwritten and picked up dynamically like the other models. You can however create your own Abstract Class and create a new address model (for example ShippingAddress) that inherits from it instead of the one included in oscar.