Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Impossible to configure #95

Closed
clincher opened this issue Sep 5, 2011 · 10 comments
Closed

Impossible to configure #95

clincher opened this issue Sep 5, 2011 · 10 comments

Comments

@clincher
Copy link

clincher commented Sep 5, 2011

Guys, i have some problem with configuring django-shop app
i set SHOP_CART_MODEL to 'apps.carts.models.MyCart'
and try two ways:
MyCart model based on Cart (like in docs on http://readthedocs.org/docs/django-shop/en/latest/howto/how-to-extend-django-shop-models.html

from shop.models import Cart
class MyCart(Cart):
class Meta(object):
pass

this raise:
django.core.exceptions.ImproperlyConfigured: Error importing backend apps.carts.models: "cannot import name Cart". Check your SHOP_CART_MODEL setting

and MyCart model based on BaseCart

from shop.models.defaults.bases import Cart
class MyCart(Cart):
class Meta(object):
pass

it raise:
django.core.exceptions.ImproperlyConfigured: Backend module "apps.carts.models" does not define a "MyCart" class.

it takes me much time of trying to fix it. guys, please, help)

@chrisglass
Copy link
Contributor

The documentation seems not to be up-to-date anymore. Sorry about that.

Could you try the following? :

from shop.models.defaults.bases import BaseCart
class MyCart(BaseCart):
    class Meta(object):
        pass

And add this to you SHOP_CART_MODEL ?

Notice - this is similar to your second example, but in your second example MyCart still extends "Cart" - Not BaseCart.

Let me know if this helps. Once you confirm it works I'll update the docs.

@clincher
Copy link
Author

clincher commented Sep 5, 2011

Thank you for fast reply

But it does not help me and raise same
django.core.exceptions.ImproperlyConfigured: Backend module "apps.carts.models" does not define a "MyCart" class.

In my second example i mean just this, but i don't use copy-paste and rewrite first example :)

So, i still need help. In case of enmergency i have monkey patching solution, but i hate it and always try to find technological solution

@chrisglass
Copy link
Contributor

Ok, I'll investigate on my side how I do it on the sites that use this trick.
Sorry about this. I'll get back to you ASAP.

@chrisglass
Copy link
Contributor

Hi again.

I had a look at the shop where we use the model injection, and discovered that we actually rewrote models - not extended them. So a semi-ugly fix is to make your Cart extend models.Model, and re implement the methods on there. This is ugly because obviously it's not DRY, but it at least does the job until a better fix is discovered (I'll spend some of my time investigating further).

Thanks

@clincher
Copy link
Author

I think eged is better describe this problem it issue #96
In addition he suggested solutions.
Is there any progress?

@vilos
Copy link

vilos commented Sep 22, 2011

I was able to workaround the problem by modifying get_model_string() in shop.util.loader. See commit 9d63a63
Not sure how much viable solution it is generally, but works for me so far.

@bmihelac
Copy link
Contributor

Same issue applies to custom Order models as well.

UPDATE: I am not sure if it really applies to custom Order models, would have to test it further

@clincher
Copy link
Author

clincher commented Oct 7, 2011

eged, i was trying your commit and it does not work for me.
when i try syncdb i was take
Error: One or more models did not validate:
shop.cartitem: 'cart' has a relation with model apps.customshop.cart.models.Cart, which has either not been installed or is abstract.

in this case i use my model based to CartBase from defaults models. of course abstact was False

There is one case when i take a profit
I was created Cart model identical to CartBase with minor changes - app_label and abstract and it works!
But it duplicated huge chunk of code and DRY was lost :(

@vilos
Copy link

vilos commented Oct 12, 2011

Hi, my hack is vulnerable to the file structure in which the extended model is defined. It works best in simple case when extended model is in the form: customapp.models.Cart, but if you have different structure you can avoid the validation error like above by inserting the correct app_label to extended model Meta options.

@alesdotio
Copy link
Contributor

I believe this was solved in the circular import fix #125

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants