I have three models and i wanna order Products.objects.all() by is_it_good from ProductsRating model. How can i do it?
I was traing something like:
qs = Products.objects.annotate(
biggest_rating = Max('productsrating__is_it_good')
).order_by('biggest_rating')
but then i get an error "Cannot resolve keyword 'productsrating' into field"
models.py
class CusUser(AbstractUser):
pass
class Products(models.Model):
name = models.CharField(max_length=300)
category = models.CharField(max_length=300)
cost = models.IntegerField()
class ProductsRating(models.Model):
is_it_good = models.IntegerField(validators=[MaxValueValidator(0), MinValueValidator(5)])
whose_rated = models.ForeignKey(CusUser, on_delete=models.CASCADE)