You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

multi_dealer_setup.rst 1.7KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. ==========================================
  2. How to do a dashboard for multiple dealers
  3. ==========================================
  4. The use case is a website where dealers sign up for the website and can then
  5. add and manage their and only their products. This is different from a stock
  6. Oscar install, because by default, the dashboard allows managing all products.
  7. Lingo
  8. -----
  9. Dealers are understood to be users who have an associated partner instance. You
  10. can still have normal users.
  11. Make the connection
  12. -------------------
  13. Replace the Partner model. AbstractPartner already carries a ``ManyToManyField``
  14. to users, which you can use. I opted to replace that field with a
  15. ``OneToOneField``.
  16. You'll need to enforce creating of a ``StockRecord`` with every ``Product``.
  17. When a ``Product`` is created, ``Stockrecord.partner`` gets set to
  18. ``self.request.user.partner`` (created if necessary), and hence the connection
  19. is made.
  20. Filter the dashboard
  21. --------------------
  22. Every view that returns a list of products needs to be adapted to only return
  23. products that belong to the dealer::
  24. # views.py
  25. class FilteredProductListView(ProductListView):
  26. def get_queryset(self):
  27. qs = super(FilteredProductListView, self).get_queryset()
  28. partner = self.request.user.partner
  29. return qs.filter(stockrecord__partner=partner)
  30. This could turn into quite a bit of work.
  31. Luckily most deployments will use a heavily reduced dashboard, consequently
  32. reducing the necessary work.
  33. Decorators
  34. ----------
  35. Dashboard access is limited to staff users by default. You'll need to replace
  36. the decorators with a ``login_required`` decorator.
  37. Dashboard navigation
  38. --------------------
  39. Can be adjusted by tweaking the ``OSCAR_DASHBOARD_NAVIGATION`` setting.