Advertisement
Guest User

Untitled

a guest
Jun 27th, 2019
137
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.88 KB | None | 0 0
  1. class Profile(models.Model):
  2. user = models.OneToOneField(User, on_delete = models.CASCADE)
  3. fullname = models.CharField(max_length=100, null=True)
  4. dob = models.DateField(null=True)
  5. address = models.TextField(null=True)
  6. city = models.CharField(max_length=100, null=True)
  7. country = models.CharField(max_length=100, null=True)
  8. profilephoto = models.ImageField(default='profiles/default_profile.jpg', upload_to='profiles')
  9.  
  10. class Product(models.Model):
  11. name = models.CharField(max_length=100)
  12. brand = models.CharField(max_length=100)
  13. cost = models.DecimalField(max_digits=8, decimal_places=2, default=0.00)
  14. category = models.CharField(max_length=100)
  15. releasedate = models.DateField()
  16. description = models.TextField()
  17. productphoto = models.ImageField(default='products/default_product.jpg', upload_to='products')
  18.  
  19. class Review(models.Model):
  20. product = models.ForeignKey(Product, on_delete=models.CASCADE)
  21. profile = models.ForeignKey(Profile, on_delete=models.CASCADE)
  22. author = models.ForeignKey(User, on_delete=models.CASCADE)
  23. rating = models.PositiveSmallIntegerField(default=1, validators = [MinValueValidator(1), MaxValueValidator(5)])
  24. reviewtext = models.TextField()
  25. postdate = models.DateTimeField(auto_now_add=True)
  26. lastmodified = models.DateTimeField(auto_now=True)
  27.  
  28. class ProductDetailView(TemplateView):
  29. # template_name = 'reviewApp/test.html'
  30. template_name = 'reviewApp/product_detail.html'
  31. def get_context_data(self, **kwargs):
  32. prod = self.kwargs['pk']
  33. context = super(ProductDetailView, self).get_context_data(**kwargs)
  34. context['Products'] = Product.objects.filter(id=prod)
  35. context['Reviews'] = Review.objects.filter(product=prod)
  36. prof = Review.objects.only('profile_id')
  37. context['Profiles'] = Profile.objects.filter(id__in=prof)
  38. return context
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement