Using shop.util.loader.get_model_string for base models outside scope shop

27 views
Skip to first unread message

jrief

unread,
Feb 9, 2012, 3:15:48 AM2/9/12
to djang...@googlegroups.com
Hi,
in my module productvariations, I wanted to implement an abstract base model together with a derived model for the default case. In order to to so, I wanted to use the function shop.util.loader.get_model_string(model_name).
My problem is, that in the default case, the function returns a model in the namespace of shop, which of course is not what I want. So, shall I add a default argument to this function, where I can override line
72          return 'shop.%s' % model_name
with an alternative namespace, or is there a better solution?

Cheers, Jacob

Simon Luijk

unread,
Feb 9, 2012, 5:31:45 AM2/9/12
to djang...@googlegroups.com
There is a fix in https://github.com/divio/django-shop/pull/125 that will solve this
by allowing SHOP_X_MODEL to be set to a tuple with two elements. The second
element would be the required namespace.

--
Simon

jrief

unread,
Feb 9, 2012, 6:09:32 AM2/9/12
to djang...@googlegroups.com
Hello Simon,
I already pulled that fix in, but its not what I need.
The default case shall be self contained and I do not want to have to set any SHOP_X_MODEL in settings.py.
This small patch could fix it: 

Jacob

Simon Luijk

unread,
Feb 9, 2012, 9:02:28 AM2/9/12
to djang...@googlegroups.com
The only benefit of using that function over just entering a string is if this in being used in a
reusable app. I think your patch makes sense in that case. If your not expecting anyone
to override the setting you might be better off just entering a string though.

On a project I am working on I had allot of model code coming from many different apps and
glue code. It was causing a few issues with schema/data migrations, in the end putting
all the models within the 'shop' namespace but staying in their respective packages and
setting an entry for 'shop' in SOUTH_MIGRATION_MODULES solved the problem.

--
Simon

jrief

unread,
Feb 9, 2012, 9:25:50 AM2/9/12
to djang...@googlegroups.com
Hello Simon,
yes, my intention is to write a reusable module. For normal requirements, I want to offer a default model without any need for configuration. But for special requirements, the model shall be overridable by adding a SHOP_X_MODEL to the app's settings.py. Sure I could add a wrapper function to my module which emulates get_model_string and checks if SHOP_X_MODEL is set. If the patch is rejected, thats my backup plan.

Using SOUTH_MIGRATION_MODULES seems to be an idea worth looking at. I will give it a try.

Jacob
Reply all
Reply to author
Forward
0 new messages