Reputation: 513
I am trying to fork django-oscar to change the dashboard form for product attributes, multioption. Need to have a description field for every option.
project/oscar_fork/catalogue/models.py:
from django.db import models
from django.utils.translation import ugettext_lazy as _
from oscar.apps.catalogue.abstract_models import AbstractAttributeOption, AbstractAttributeOptionGroup
class AbstractAttributeOption(AbstractAttributeOption):
description = models.CharField(_('Description'), max_length=250, blank=True)
group = models.ForeignKey(
'catalogue.AttributeOptionGroup',
on_delete=models.CASCADE,
related_name='optionsblabla',
verbose_name=_("Group"))
from oscar.apps.catalogue.models import *
The models are changed with the extra field "description" in my DB, but still my form field returns cannot find this field.
project/oscar_fork/dashboard/catalogue/forms.py:
from oscar.apps.dashboard.catalogue import forms as base_forms
class AttributeOptionForm(base_forms.AttributeOptionForm):
class Meta(base_forms.AttributeOptionForm.Meta):
fields = ('option', 'description')
If I change the form.py and models.py fields directly in the Oscar app it works. Other forms can be forked that easily as shown above. Tried it with AttributeOptionGroupForm. I think there is a problem with the sequence of import. How can I solve this?
Error:
django.core.exceptions.FieldError: Unknown field(s) (description) specified for AttributeOption
I am using django-oscar v1.6. Django v.2.08.
Upvotes: 1
Views: 257
Reputation: 73470
Your concrete model should be named AttributeOption
without the 'Abstract'
, otherwise oscar will not pick it up and use its own AttributeOption
model instead, which has no description:
class AttributeOption(AbstractAttributeOption):
description = ...
You will have to run makemigrations
and migrate
after that.
Check the source code of the models
module that you import at the end. You will see how their dynamic model loading works:
if not is_model_registered('catalogue', 'AttributeOption'):
class AttributeOption(AbstractAttributeOption):
pass
Upvotes: 2