igorsimb / mp-monitor

Django app for scraping Wildberries
1 stars 0 forks source link

[bug] For superuser - If different users have same item, going to `item_detail` page return `Item.MultipleObjectsReturned` error #105

Closed igorsimb closed 5 months ago

igorsimb commented 5 months ago

Also item_list shows the item twice now. Only for superuser

igorsimb commented 5 months ago

Solution

Override get_queryset in both: the itemListView and ItemDetailView

class ItemListView(PermissionListMixin, ListView):
    # ...  other code as before ...

    def get_queryset(self):
        tenant = self.request.user.tenant
        return Item.objects.filter(tenant=tenant)