Есть 3 модели, я хочу выполнить запрос, подобный этому
выберите article_id из voice_vote, где user_id = user.id и значение = True
с формой Я пробую это
Article.objects.filter (author = user.id, likes = True)
Голосовать
class Vote(models.Model):
value = models.NullBooleanField()
user = models.ForeignKey(User,
on_delete=models.CASCADE)
article = models.ForeignKey(Article,
on_delete=models.CASCADE,
related_name='likes')
voted_on = models.DateTimeField(
auto_now=True
)
артикул
class Article(models.Model):
author = models.ForeignKey(User, on_delete=models.CASCADE)
slug = models.SlugField(db_index=True, unique=True, max_length=255)
title = models.CharField(max_length=255)
subtitle = models.CharField(blank=True, max_length=400)
# El campo RichTextUploading lo heredo de CKEDITOR
body = RichTextUploadingField()
image = models.ImageField(upload_to='featured_image', blank=True)
created_at = models.DateTimeField(auto_now_add=True)
updated_at = models.DateTimeField(auto_now=True)
пользователь
class User(AbstractUser):
# Lista de cohortes de Academlo
COURSE_START = [
('J2019', 'Julio 2019'),
('E2020', 'Enero 2020'),
('M2020', 'Mayo 2020'),
]
GENDER = [
('M', 'Hombre'),
('F', 'Mujer')
]
# Campos de usuario
first_name = models.CharField(max_length=200, blank=False)
last_name = models.CharField(max_length=200, blank=False)
username = models.CharField(max_length=200, blank=False, unique=True)
email = models.EmailField(unique=True, max_length=300, blank=False)
course = models.CharField(choices=COURSE_START, max_length=5)
gender = models.CharField(choices=GENDER, max_length=1)