hi everyone i am building a ecommerce webapp where everything is done except this. i want the user to get the product that it posted by itself my views.py file is:
class UserPostListView(ListView):
model = Product
template_name = 'product/user-posts.html'
def get_queryset(self):
user = get_object_or_404(User, email=self.kwargs.get('email'))
return Product.objects.filter(author=user , is_staff=True).order_by('-date_posted')my urls.py file is:
urlpatterns = [
# path('featured/' , ProductFeaturedListView.as_view()),
#path('featured/<int:pk>' , ProductFeaturedDetailView.as_view()),
path('' , ProductListView.as_view(), name= "list"),
path('new/' , ProductCreateView.as_view() , name="product-create"),
path('<slug:slug>/update/' , ProductUpdateView.as_view() , name="product-update"),
path('<slug:slug>/delete/' , ProductDeleteView.as_view() , name="product-delete"),
#path('product-fbv/' , product_list_view),
#path('product/<int:pk>' , ProductDetailView.as_view()),
path('<slug:slug>/comment' , CommentCreateView.as_view() , name="add-comment"),
path('<slug:slug>' , ProductDetailSlugView.as_view() , name="detail"),
path('userpost/', UserPostListView.as_view(), name='user-post'),
# path('product-fbv/<int:pk>' , product_detail_view),
]and my user model is:
class User(AbstractBaseUser):
email = models.EmailField(max_length=255 ,unique=True)
full_name = models.CharField(max_length=255, blank=True, null=True)
active = models.BooleanField(default=True) #can login
staff = models.BooleanField(default=False) #staff user non super user
admin = models.BooleanField(default=False) #superuser
time_stamp = models.DateTimeField(auto_now_add=True)class Product(models.Model):
title = models.CharField(max_length=110)
slug = models.SlugField(blank=True, unique=True)
status = models.CharField(choices=CATEGORY_CHOICES, max_length=10)
price = models.DecimalField(decimal_places=2, max_digits=6)
discount_price=models.FloatField(blank=True, null=True)
size = models.CharField(choices=SIZE_CHOICES, max_length=20)
color = models.CharField(max_length=20, blank=True, null=True)
image = models.ImageField(upload_to=upload_image_path)
description = RichTextField(max_length=1000)
featured = models.BooleanField(default=False)
author = models.ForeignKey(User, on_delete=models.CASCADE)
time_stamp = models.DateTimeField(auto_now_add=True)and it give me the error that no user matches the given query
Aucun commentaire:
Enregistrer un commentaire