Extending non abstract Oscar models.

195 views
Skip to first unread message

Wiesław Górniewski

unread,
Apr 30, 2015, 7:00:49 AM4/30/15
to django...@googlegroups.com
Hi, in our project we try to extend Oscar non abstract models with extra choices/fiedls/etc. 
Django version is 1.7.7, Oscar version 1.0.2 final.
Problem is we always get error similar to this:

File "/home/wigo/.virtualenvs/oskarek/local/lib/python2.7/site-packages/django/apps/registry.py", line 221, in register_model
   
(model_name, app_label, app_models[model_name], model))
RuntimeError: Conflicting 'condition' models in application 'offer': <class 'oscar.apps.offer.models.Condition'> and <class 'oskarek.offer.models.Condition'>.


This is how our offer/models.py file look right now (simplest possible model inheritance):

from oscar.apps.offer.models import Condition as OscarCondition


class Condition(OscarCondition):
    pass

I have also tried other ways of extending non abstract models, given in this thread: https://groups.google.com/forum/#!topic/django-oscar/8W_Rmwk6wiU
Any way produces error given above.

Please, help.
Wieslaw. :) 

BugSpencer

unread,
Apr 30, 2015, 6:43:02 PM4/30/15
to django...@googlegroups.com
Il giorno giovedì 30 aprile 2015 13:00:49 UTC+2, Wiesław Górniewski ha scritto:
I have also tried other ways of extending non abstract models, given in this thread: https://groups.google.com/forum/#!topic/django-oscar/8W_Rmwk6wiU
Any way produces error given above.

Please, help.
Wieslaw. :) 

Hi Wieslaw, I think the problem here is "not" in offer/models.py, but in offer/views.py:
Django 1.7 requires you to always reference a model with same class name from same path,
even if you don't actually use it. The right way to deal with this is to use get_model.

a couple of models are imported directly, hence reading oscar's models.py.
From that point onwards, any model you try to override, you'll get that error, since your models
will have 2 different entry points.

I think your best bet is to fork oscar and replace that single line with "get model" equivalent,
or try to avoid oscar's views.py from being loaded at all, if you can (I had problems with this approach),
given this is just an "oversight", and not an undocumented (?) design decision.

Long story short: you cannot fork offer models as easy as with other apps.

Hope it helps,
Luca

Wiesław Górniewski

unread,
May 1, 2015, 12:28:02 PM5/1/15
to django...@googlegroups.com
Hi Luca, 

I created fork of Oscar 1.0.2 and changed two files in offer app:

custom.py

from oscar.core.loading import get_model
# from oscar.apps.offer.models import Range, Condition, Benefit
Benefit = get_model('offer', 'Benefit')
Range = get_model('offer', 'Range')
Condition = get_model('catalogue', 'Condition')

views.py

from oscar.core.loading import get_model
# from oscar.apps.offer.models import ConditionalOffer, Range
ConditionalOffer = get_model('offer', 'ConditionalOffer')
Range = get_model('offer', 'Range')
Product = get_model('catalogue', 'Product')

Unfortunately problem still exists. 

1. When importing

as OscarCondition

we have error 'RuntimeError: Conflicting 'condition' models in application 'offer': <class 'oscar.apps.offer.models.Condition'> and <class 'offer.models.Condition'>.'

2. When importing in our custom app using get model 

from django.db.models.loading import get_model
OscarCondition = get_model('offer', 'Condition')


class Condition(OscarCondition):
   
pass


here is what we get:

django.core.exceptions.AppRegistryNotReady: Models aren't loaded yet.

In your case, did you end up disabling loading for Oscar views, or did you create fork of Oscar and changed way of importing?

Thanks,
Wieslaw

BugSpencer

unread,
May 1, 2015, 1:54:52 PM5/1/15
to django...@googlegroups.com
Il giorno venerdì 1 maggio 2015 18:28:02 UTC+2, Wiesław Górniewski ha scritto:
Hi Luca, 

I created fork of Oscar 1.0.2 and changed two files in offer app:

In your case, did you end up disabling loading for Oscar views, or did you create fork of Oscar and changed way of importing?

Luckily, in my case I realized that I didn't really need to override offer models to achieve my goal,
so I didn't go any further.

Anyway what worked for me was to fork oscar and change explicit imports with calls to get_model,
to make sure that "oscar.apps.offer.model was never referenced. My work was based on master branch
(approximately 2 weeks ago), not on 1.0.2, don't know if this makes any difference.

I'll try to dig and see if I can make it work again and eventually send a PR.

BugSpencer

unread,
May 2, 2015, 7:41:34 AM5/2/15
to django...@googlegroups.com
Il giorno venerdì 1 maggio 2015 19:54:52 UTC+2, BugSpencer ha scritto:
I'll try to dig and see if I can make it work again and eventually send a PR.

Wiesław Górniewski

unread,
May 5, 2015, 4:51:47 AM5/5/15
to django...@googlegroups.com
W dniu sobota, 2 maja 2015 12:41:34 UTC+1 użytkownik BugSpencer napisał:


Thanks for help Luca, at least we know where we stand now. We will try to use this branch for development maybe.

regards,
Wieslaw  

Michael van Tellingen

unread,
May 5, 2015, 5:22:39 AM5/5/15
to django...@googlegroups.com
Hi Wieslaw,

I intent to merge #1721 after i've tested if it works correctly in a project where some of the models are overridden. If you als like to test against it then  thats much appreciated :-)

Regards,
Michael





--
https://github.com/tangentlabs/django-oscar
http://django-oscar.readthedocs.org/en/latest/
https://twitter.com/django_oscar
---
You received this message because you are subscribed to the Google Groups "django-oscar" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-oscar...@googlegroups.com.
Visit this group at http://groups.google.com/group/django-oscar.
To view this discussion on the web, visit https://groups.google.com/d/msgid/django-oscar/d5e5e091-0141-41ac-b053-3f0b45e01ed9%40googlegroups.com.

For more options, visit https://groups.google.com/d/optout.

Reply all
Reply to author
Forward
0 new messages