Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Profile(models.Model):
- user = models.OneToOneField(User, on_delete = models.CASCADE)
- fullname = models.CharField(max_length=100, null=True)
- dob = models.DateField(null=True)
- address = models.TextField(null=True)
- city = models.CharField(max_length=100, null=True)
- country = models.CharField(max_length=100, null=True)
- profilephoto = models.ImageField(default='profiles/default_profile.jpg', upload_to='profiles')
- class Product(models.Model):
- name = models.CharField(max_length=100)
- brand = models.CharField(max_length=100)
- cost = models.DecimalField(max_digits=8, decimal_places=2, default=0.00)
- category = models.CharField(max_length=100)
- releasedate = models.DateField()
- description = models.TextField()
- productphoto = models.ImageField(default='products/default_product.jpg', upload_to='products')
- class Review(models.Model):
- product = models.ForeignKey(Product, on_delete=models.CASCADE)
- profile = models.ForeignKey(Profile, on_delete=models.CASCADE)
- author = models.ForeignKey(User, on_delete=models.CASCADE)
- rating = models.PositiveSmallIntegerField(default=1, validators = [MinValueValidator(1), MaxValueValidator(5)])
- reviewtext = models.TextField()
- postdate = models.DateTimeField(auto_now_add=True)
- lastmodified = models.DateTimeField(auto_now=True)
- class ProductDetailView(TemplateView):
- # template_name = 'reviewApp/test.html'
- template_name = 'reviewApp/product_detail.html'
- def get_context_data(self, **kwargs):
- prod = self.kwargs['pk']
- context = super(ProductDetailView, self).get_context_data(**kwargs)
- context['Products'] = Product.objects.filter(id=prod)
- context['Reviews'] = Review.objects.filter(product=prod)
- prof = Review.objects.only('profile_id')
- context['Profiles'] = Profile.objects.filter(id__in=prof)
- return context
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement