【发布时间】:2020-07-24 00:47:19
【问题描述】:
Models.py,来自 django admin 我所做的是我可以将产品添加到 Featured 但问题是当我在 admin 中选择一个产品以使其成为特色时,我想自动继承该产品上传的图片 url该产品的创建时间。
class Product(models.Model):
seller = models.ForeignKey(Seller, on_delete=models.CASCADE)
title = models.CharField(max_length=120, primary_key=True)
image = models.FileField()
def __str__(self):
return self.title
class FeaturedProduct(models.Model):
db_identification = models.CharField(max_length=120)
featured = models.ForeignKey(Product, on_delete=models.CASCADE)
photograph = How do I inherit it automatically from foreignkey product selected?
timestamp = models.DateTimeField(auto_now_add=True)
def __str__(self):
return self.db_identification
【问题讨论】:
标签: python django database django-models django-rest-framework