Model Customization and Oscar Administration Panel

105 views
Skip to first unread message

christia...@abinsula.com

unread,
Apr 14, 2016, 12:04:46 PM4/14/16
to django-oscar
Hi A/all,
I'm trying to modify OSCAR "Product" model, in order to add fields to the model.
These are steps I followed:

1) For of the catalogue app
2) Created my custom Product as follows:

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

class Author(models.Model):
    name = models.CharField(max_length=300, null=False)
    birthdate = models.DateField(null=True)
    biography = models.TextField(blank=True, null=True)
    picture = models.ImageField(null=True)

class Product(AbstractProduct):
    author = models.ManyToManyField(to='Author', related_name='authors', blank=False)
    synopsys = models.TextField(blank=True, null=True)



#Stands at the bottom of the declaration
from oscar.apps.catalogue.models import *  # noqa

3) Applied migrations.

Everything goes right but... How can I reflect my changes in the administration panel in order to Add models and edit existing ones?

Thanks in advance,
Christian

Sergey Maranchuk

unread,
Apr 23, 2016, 3:45:13 AM4/23/16
to django-oscar
from django.contrib import admin
from oscar.apps.catalogue.admin import *
from .models import Product


admin
.site.unregister(ProductAdmin)

@admin.register(Product)
class CustomProductAdmin(ProductAdmin):
   fields
= ProductAdmin.fields + ['author']





четверг, 14 апреля 2016 г., 19:04:46 UTC+3 пользователь christia...@abinsula.com написал:

Davide Olianas

unread,
Feb 19, 2018, 3:52:33 PM2/19/18
to django-oscar
This doesn't work with Oscar 1.5.2 and Django 1.11.10.

I get the following traceback

Unhandled exception in thread started by <function check_errors.<locals>.wrapper at 0x7f46d425a488>
Traceback (most recent call last):
  File "/home/davide/progetti/django-oscar-paypal/sandbox/venv35/lib/python3.5/site-packages/django/utils/autoreload.py", line 228, in wrapper
    fn(*args, **kwargs)
  File "/home/davide/progetti/django-oscar-paypal/sandbox/venv35/lib/python3.5/site-packages/django/core/management/commands/runserver.py", line 117, in inner_run
    autoreload.raise_last_exception()
  File "/home/davide/progetti/django-oscar-paypal/sandbox/venv35/lib/python3.5/site-packages/django/utils/autoreload.py", line 251, in raise_last_exception
    six.reraise(*_exception)
  File "/home/davide/progetti/django-oscar-paypal/sandbox/venv35/lib/python3.5/site-packages/django/utils/six.py", line 685, in reraise
    raise value.with_traceback(tb)
  File "/home/davide/progetti/django-oscar-paypal/sandbox/venv35/lib/python3.5/site-packages/django/utils/autoreload.py", line 228, in wrapper
    fn(*args, **kwargs)
  File "/home/davide/progetti/django-oscar-paypal/sandbox/venv35/lib/python3.5/site-packages/django/__init__.py", line 27, in setup
    apps.populate(settings.INSTALLED_APPS)
  File "/home/davide/progetti/django-oscar-paypal/sandbox/venv35/lib/python3.5/site-packages/django/apps/registry.py", line 116, in populate
    app_config.ready()
  File "/home/davide/progetti/django-oscar-paypal/sandbox/venv35/lib/python3.5/site-packages/django/contrib/admin/apps.py", line 23, in ready
    self.module.autodiscover()
  File "/home/davide/progetti/django-oscar-paypal/sandbox/venv35/lib/python3.5/site-packages/django/contrib/admin/__init__.py", line 26, in autodiscover
    autodiscover_modules('admin', register_to=site)
  File "/home/davide/progetti/django-oscar-paypal/sandbox/venv35/lib/python3.5/site-packages/django/utils/module_loading.py", line 50, in autodiscover_modules
    import_module('%s.%s' % (app_config.name, module_to_search))
  File "/usr/lib/python3.5/importlib/__init__.py", line 126, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "<frozen importlib._bootstrap>", line 986, in _gcd_import
  File "<frozen importlib._bootstrap>", line 969, in _find_and_load
  File "<frozen importlib._bootstrap>", line 958, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 673, in _load_unlocked
  File "<frozen importlib._bootstrap_external>", line 665, in exec_module
  File "<frozen importlib._bootstrap>", line 222, in _call_with_frames_removed
  File "/home/davide/progetti/django-oscar-paypal/sandbox/apps/catalogue/admin.py", line 6, in <module>
    admin.site.unregister(ProductAdmin)
  File "/home/davide/progetti/django-oscar-paypal/sandbox/venv35/lib/python3.5/site-packages/django/contrib/admin/sites.py", line 135, in unregister
    for model in model_or_iterable:
TypeError: 'MediaDefiningClass' object is not iterable


Any ideas?
Reply all
Reply to author
Forward
0 new messages