Git Product home page Git Product logo

Comments (10)

chrisglass avatar chrisglass commented on July 22, 2024

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.

from django-shop.

clincher avatar clincher commented on July 22, 2024

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

from django-shop.

chrisglass avatar chrisglass commented on July 22, 2024

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.

from django-shop.

chrisglass avatar chrisglass commented on July 22, 2024

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

from django-shop.

clincher avatar clincher commented on July 22, 2024

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

from django-shop.

vilos avatar vilos commented on July 22, 2024

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.

from django-shop.

bmihelac avatar bmihelac commented on July 22, 2024

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

from django-shop.

clincher avatar clincher commented on July 22, 2024

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 :(

from django-shop.

vilos avatar vilos commented on July 22, 2024

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.

from django-shop.

alesdotio avatar alesdotio commented on July 22, 2024

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

from django-shop.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.