S
S
Sergey Nizhny Novgorod2017-06-22 02:01:44
Django
Sergey Nizhny Novgorod, 2017-06-22 02:01:44

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

1 answer(s)
A
Andrey Burov, 2017-06-22
@BuriK666

https://docs.djangoproject.com/en/dev/topics/db/qu...
someproduct.reviews_set.all()

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question