Category model extended.

40 views
Skip to first unread message

alberto....@gmail.com

unread,
Jul 15, 2016, 2:50:13 PM7/15/16
to django-oscar
Hello every one. I'm very new in django and oscar. Recently i just want to add a field to Category model, as this:


import django
from django.utils.translation import ugettext_lazy as _
from oscar.apps.catalogue.abstract_models import AbstractCategory

class Category(AbstractCategory):
seo_name = django.db.models.CharField('SeoName', max_length=255, db_index=False)

from oscar.apps.catalogue.models import *


I read documentacion, and everything seems ok. Even i could migrate db and in django admin page i can edit this new field. However in oscar default navigation, views, and forms, when i'm going to create a new category this field doesn't appear for edition.

Is it supossed with this simple model extension, the default form should detect, and edit this field?

I have digged a bit in Oscar implemetation and I have realized there is no a CategoryForm on oscar in order to change it, but there is a CategoryCreateView and CategoryUpdateView, even the CategoryForm is created dynamically and this views uses thouse classes.

I want to know if there is a simple way to use the default oscar forms/views in order to edit this field.

Thanks ins advance.
Albert.

Van Tran

unread,
Jul 17, 2016, 1:37:51 PM7/17/16
to django-oscar
Dear Albert,

Django-oscar has CategoryForm class in /src/oscar/apps/dashboard/catalogue/forms.py

CategoryForm = movenodeform_factory(
    Category,
    fields=['name', 'description', 'image'])

You should override CategoryForm like that:
CategoryForm = movenodeform_factory(
    Category,
    fields=['name', 'description', 'image', 'seo_name'])

Hope this help,

Tran Van

Vào 01:50:13 UTC+7 Thứ Bảy, ngày 16 tháng 7 năm 2016, alberto....@gmail.com đã viết:
Reply all
Reply to author
Forward
0 new messages