Answer the question
In order to leave comments, you need to log in
Unclear response when querying Djnago?
Everything seems ok returns me
[<UserLikes: UserLikes object>, <UserLikes: UserLikes object>]
current_user = int(request.user.id)
liked_posts = UserLikes.objects.filter(user_id=current_user)
<center>{{all_likes}} </center>
class UserLikes(models.Model):
user_id = models.IntegerField(blank=True,default=1)
id_post= models.IntegerField(blank=True)
Answer the question
In order to leave comments, you need to log in
1. While reading the question, I broke my tongue five times and my eyes three times.
2. Please try PHP. In Python, programmers who can't write well in their native language don't survive. Or try to formulate your question in any other language (including Korean). I'm sure you'll be more willing to help.
3. This code will probably work like this:
# views.py
liked_post_ids = UserLikes.objects.filter(user=request.user).values_list('id', flat=True)
# template.html
{% if post.id in liked_posts_ids %}
This post was already liked.
{% else %}
You can like this post.
{% endif %}
# models.py
from django.contrib.auth.models import User
from django.db import models
class Post(models.Model):
user = models.ManyToManyField(User)
slug = models.SlugField()
You got a bunch of misconceptions about the architecture
request.user - indicates the current authorized user,
I logged in, and through request.user I can filter what I did.
The appearance of such fields indicates that something went wrong
user_id = models.IntegerField()
id_post= models.IntegerField()
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question