class Movie(models.Model):
production_house = models.CharField(max_length=50)
title = models.CharField(max_length=100)
genre = models.CharField(max_length=100)
year = models.IntegerField()
created_at = models.DateTimeField(auto_now_add=True) # When it was create
updated_at = models.DateTimeField(auto_now=True) # When i was update
creator = models.ForeignKey('auth.User', related_name='movies', on_delete=models.CASCADE)
class ProductionHouse(models.Model):
p_name = models.CharField(max_length=50)
p_address = models.CharField(max_length=100)
owner = models.CharField(max_length=50)
我正在做一个现有的项目,所有的表都是平的,没有外键。我必须返回来自两个表的查询。看看模型,我需要把ProductionHouse作为关键,这个ProductionHouse制作的所有电影都会有价值。为了提高的清晰度
"ProductionHouse1":{"标题":"标题1";"generae":"generae1";所有字段},{"标题":"标题2";"流派":"generae3";所有字段}
"ProductionHouse2":{"标题":"标题1";"流派":"generae1";所有字段},
或简单"productionHouse1":{电影查询集1电影查询集2电影查询集3。。。},"productionHouse2":{
电影查询集1。。。},等等
class MovieProductionSerializer(serializers.ModelSerializer):
movies= MovieSerializer(many=True, read_only=True)
class Meta:
model= ProductionHouse
fields=['id','title','production_house',
'created_at','updated_at','year', 'creater','movies'
]