【发布时间】:2018-05-03 09:14:19
【问题描述】:
嗨,实际上我是 django Restframe 工作的新手。 在这里我提到了我的模型我的问题是?我不知道如何存储每个产品的计数。并且浏览次数最多的产品应该显示在前端。
MODEL.PY
class Products(models.Model):
name = models.CharField(max_length=100)
image = models.CharField(max_length=10, null=True)
categories = models.ArrayModelField(
model_container=Category,
model_form_class=CategoryForm
)
specifications = models.ArrayModelField(
model_container=Specifications,
model_form_class=SpecificationsForm
)
description = models.CharField(max_length=500)
reviews = models.ArrayModelField(
model_container=Reviews,
model_form_class=ReviewsForm
)
drizzly = models.BooleanField(default=False)
complete = models.BooleanField(default=False)
comment = models.CharField(max_length=500)
count = models.IntegerField()
【问题讨论】:
-
在您的视图中,您可以调用一个函数,每次用户调用该视图时,该函数会将 1 添加到您的
count模型字段。但问题是,如果用户多次点击产品,它会计算每次点击。因此,要正确执行此操作,您需要保存用户 ID /IP 地址,并且仅在用户从未查看过产品时添加一个...
标签: django django-models django-forms django-rest-framework django-views