rateing system
This commit is contained in:
@@ -493,3 +493,37 @@ class ProductVariant(DirtyFieldsMixin, models.Model):
|
||||
def save(self, *args, **kwargs):
|
||||
self.set_or_update_price()
|
||||
super().save(*args, **kwargs)
|
||||
|
||||
class ProductRating(models.Model):
|
||||
RATING_CHOICES = (
|
||||
(1, '1 - بسیار ضعیف'),
|
||||
(2, '2 - ضعیف'),
|
||||
(3, '3 - متوسط'),
|
||||
(4, '4 - خوب'),
|
||||
(5, '5 - عالی'),
|
||||
)
|
||||
|
||||
product = models.ForeignKey(
|
||||
ProductModel, on_delete=models.CASCADE, related_name='ratings', verbose_name='محصول')
|
||||
user = models.ForeignKey(
|
||||
User, on_delete=models.CASCADE, related_name='product_ratings', verbose_name='کاربر')
|
||||
rating = models.PositiveIntegerField(
|
||||
choices=RATING_CHOICES, verbose_name='امتیاز')
|
||||
created_at = models.DateTimeField(
|
||||
auto_now_add=True, verbose_name='تاریخ ایجاد')
|
||||
updated_at = models.DateTimeField(
|
||||
auto_now=True, verbose_name='تاریخ آپدیت')
|
||||
|
||||
class Meta:
|
||||
verbose_name = 'امتیاز محصول'
|
||||
verbose_name_plural = 'امتیازات محصول'
|
||||
unique_together = ('product', 'user')
|
||||
ordering = ['-created_at']
|
||||
indexes = [
|
||||
models.Index(fields=['product'], name='rating_product_idx'),
|
||||
models.Index(fields=['user'], name='rating_user_idx'),
|
||||
models.Index(fields=['rating'], name='rating_rating_idx'),
|
||||
]
|
||||
|
||||
def __str__(self):
|
||||
return f"{self.user} - {self.product} ({self.rating}⭐)"
|
||||
Reference in New Issue
Block a user