Only list products from approved sellers on customer website
All checks were successful
Deploy Beta (NATIVE) / deploy (push) Successful in 21s
All checks were successful
Deploy Beta (NATIVE) / deploy (push) Successful in 21s
This commit is contained in:
parent
cc522ab6ce
commit
17f3a6eb30
2 changed files with 30 additions and 2 deletions
|
|
@ -104,6 +104,14 @@ DATABASES = {
|
|||
'PASSWORD': 'vtechnosoft@123A',
|
||||
'HOST': '127.0.0.1',
|
||||
'PORT': '5432',
|
||||
},
|
||||
'sellerprofile': {
|
||||
'ENGINE': 'django.db.backends.postgresql',
|
||||
'NAME': 'sellerprofile',
|
||||
'USER': 'vignesh',
|
||||
'PASSWORD': 'vtechnosoft@123A',
|
||||
'HOST': '127.0.0.1',
|
||||
'PORT': '5432',
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -15,7 +15,17 @@ class ProductListView(generics.ListAPIView):
|
|||
permission_classes = [permissions.AllowAny]
|
||||
|
||||
def get_queryset(self):
|
||||
queryset = Product.objects.all()
|
||||
# Fetch approved supplier IDs from sellerprofile database
|
||||
from django.db import connections
|
||||
approved_supplier_ids = []
|
||||
try:
|
||||
with connections['sellerprofile'].cursor() as cursor:
|
||||
cursor.execute("SELECT user_id FROM api_supplierprofile WHERE status = 'approved'")
|
||||
approved_supplier_ids = [row[0] for row in cursor.fetchall()]
|
||||
except Exception as e:
|
||||
print("Error fetching approved suppliers:", e)
|
||||
|
||||
queryset = Product.objects.filter(supplier_id__in=approved_supplier_ids)
|
||||
category_slug = self.request.query_params.get('category', None)
|
||||
search_query = self.request.query_params.get('search', None)
|
||||
|
||||
|
|
@ -29,6 +39,16 @@ class ProductListView(generics.ListAPIView):
|
|||
return queryset
|
||||
|
||||
class ProductDetailView(generics.RetrieveAPIView):
|
||||
queryset = Product.objects.all()
|
||||
serializer_class = ProductSerializer
|
||||
permission_classes = [permissions.AllowAny]
|
||||
|
||||
def get_queryset(self):
|
||||
from django.db import connections
|
||||
approved_supplier_ids = []
|
||||
try:
|
||||
with connections['sellerprofile'].cursor() as cursor:
|
||||
cursor.execute("SELECT user_id FROM api_supplierprofile WHERE status = 'approved'")
|
||||
approved_supplier_ids = [row[0] for row in cursor.fetchall()]
|
||||
except Exception as e:
|
||||
print("Error fetching approved suppliers:", e)
|
||||
return Product.objects.filter(supplier_id__in=approved_supplier_ids)
|
||||
|
|
|
|||
Loading…
Reference in a new issue