5

I'm new django-oscar and my need to manage multiple seller that they can add their product and can view ie. they can have their own dashboard, I follow this url

https://django-oscar.readthedocs.org/en/releases-0.6/howto/multi_dealer_setup.html

and override oscar partner model like:-

from django.db import models
from oscar.apps.partner.abstract_models import AbstractPartner
from oscar.core.compat import AUTH_USER_MODEL
from django.utils.translation import ugettext_lazy as _

class Partner(AbstractPartner):
 user = models.OneToOneField(
        AUTH_USER_MODEL, related_name="partner",
        blank=True, verbose_name=_("Users"))

from oscar.apps.partner.models import *

Now the above link has a line that I am not getting

"You’ll need to enforce creating of a StockRecord with every Product. When a Product is created, Stockrecord.partner gets set to self.request.user.partner (created if necessary), and hence the connection is made."

If anyone have any idea about my problem then please let me know, how can I achieve it.

Thanks in Advance :-)

Mahendra Garg
  • 516
  • 1
  • 9
  • 27
  • when I migrate above model after that I try to create partner I am getting Integrity error. if any one have any idea about how to manage multiple account for dashboard then please let me know. – Mahendra Garg Mar 16 '16 at 10:10

1 Answers1

0

It means that whenever you create a new Product object you need to create a new StockRecord object for it as well. The StockRecord object contains information like the price of the product, the currency and the partner / seller that provides it. Since you decided to have multiple partners, you will need to connect the new products that you create to a partner that provides them.

Something like this:

from oscar.core.loading import get_model

Product = get_model('catalogue', 'Product')
ProductClass = get_model('catalogue', 'ProductClass')
Partner = get_model('partner', 'Partner')
StockRecord = get_model('partner', 'StockRecord')

shoes = ProductClass.objects.get(name='Shoes')
nike_air = Product.objects.create(title='Nike Air', product_class=shoes)
nike = Partner.objects.get(name='Nike')
stock_record = StockRecord.objects.create(
    partner=nike,
    partner_sku='nike-air-123'
    product=nike_air,
    price_currency='EUR',
    price_excl_tax='200'
)
Vedran
  • 1,113
  • 1
  • 17
  • 36