Answer the question
In order to leave comments, you need to log in
How to get a foreign key attribute that in turn refers to another foreign key?
Hello, this is the question, let's say I have the following model:
class Gallery(models.Model):
product = models.ForeignKey(Product, on_delete=models.CASCADE)
image = models.ImageField(upload_to=f'products/', blank=True)
class Product(models.Model):
sub_category = models.ForeignKey(SubCategory, related_name='products', on_delete=models.CASCADE)
class SubCategory(models.Model):
category = models.ForeignKey(Category, on_delete=models.CASCADE)
class Category(models.Model):
name = models.CharField(max_length=200, db_index=True)
Answer the question
In order to leave comments, you need to log in
upload_to can be a function, the telepathic third dot blinks that way.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question