Answer the question
In order to leave comments, you need to log in
How to access model foreign key data from model method?
Hello.
There are two models: the product model and the recall model.
Objective: Pull scores from all associated review models to form a global score for the product.
Question: is it possible to somehow implement this through the method of product models? If not, where is the right place to put it?
class Product(models.Model):
title = models.CharField()
class Review(models.Model):
review_connection = models.ForeignKey(Product, on_delete=models.CASCADE, default=1)
thumbnumber = models.IntegerField()
Answer the question
In order to leave comments, you need to log in
https://docs.djangoproject.com/en/dev/topics/db/qu...someproduct.reviews_set.all()
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question