user2239318
user2239318

Reputation: 2784

django-oscar extend Option model

I need to add a sequence field to Option to sort them, (right now these get alphabetical order) and add a choices on type of fields.

I've looked at docs and done this to customize the catalogue app:

./manage.py oscar_fork_app catalogue catalogue_custom

replaced the app in settings.py then tried this in new app:

catalogue_custom/catalogue/models.py

from oscar.apps.catalogue.models import *  # noqa isort:skip
from oscar.apps.catalogue.models import Option

class Option(object):
        pass

But from shell it's still the original model used.

In [1]: Option
Out[1]: oscar.apps.catalogue.models.Option

The model that need to be overwritten is defined here: https://github.com/django-oscar/django-oscar/blob/master/src/oscar/apps/catalogue/models.py

or at line 1207: https://github.com/django-oscar/django-oscar/blob/ffcc530844d40283b6b1552778a140536b904f5f/src/oscar/apps/catalogue/abstract_models.py#L1207

?

Thank you

Upvotes: 0

Views: 222

Answers (1)

user2239318
user2239318

Reputation: 2784

SOLVED:

from django.db import models
from oscar.apps.catalogue.abstract_models import AbstractOption

class Option(AbstractOption):
    default = models.CharField("Default", max_length=255, null=True)
    sequence = models.IntegerField("Sort", default=0 )

    class Meta:
        ordering = ['sequence']



from oscar.apps.catalogue.models import *  

Just works like a charm.


Anyway I've extended original project and sent a pull request, any mantainer can review this please?

https://github.com/django-oscar/django-oscar/pull/3852


@solarissmoke, the pull have not been reviewed yet. why did you remove the pull request from this message?

Upvotes: 0

Related Questions