Answer the question
In order to leave comments, you need to log in
Django tracking of viewed posts?
Hello!
It is necessary to implement the account of viewed posts for each user, I implement models.py like this:
class CountArticle(models.Model):
user = models.OneToOneField(User)
count = models.ManyToManyField(Article)
def total_count(request):
def init_count(request):
# add to CountArticle model Article list
count = CountArticle.objects
usr = request.user
art = Article.objects.all()
art_add = Article.objects
count.create(user=usr)
count = CountArticle.objects.get(user=usr)
for x in art:
count.count.add(art_add.get(article_title=x))
return {"total_count": len(count.count.all()), }
if request.user.is_authenticated():
try:
total = CountArticle.objects.get(user=request.user)
return {"total_count": len(total.count.all()), }
except ObjectDoesNotExist:
return init_count(request)
return {}
Answer the question
In order to leave comments, you need to log in
sqlite - a database for development, no one puts it in production Measure
the speed on it, seriously, no
one does it anymore https://docs.djangoproject.com/en/1.9/topics/auth/...
techydiary.com /how-to-customize-user-model-in-django1-5 field name does not match the content
"initialize" m2m is not necessary
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question