当序列化子对象时,我需要从父级获取json数据。 这意味着每个孩子的json对象必须包含来自父级的json数据。
class player(Model):
name = models.CharField(max_length=30)
family = models.CharField(max_length=50)
state = models.CharField(max_length=50, verbose_name='استان')
team = models.ForeignKey(team,on_delete=models.CASCADE)
class warning(Model):
refereereportkey = models.ForeignKey(refereereport, on_delete=models.CASCADE,related_name='Warnings')
player = models.ForeignKey(player,on_delete=models.CASCADE,related_name='Players')
playernumber = models.IntegerField()
minute = models.IntegerField()
reason = models.TextField()
class PlayerSerializer(serializers.ModelSerializer):
class Meta:
model = player
fields=('name','family','state','team')
class WarningSerializer(serializers.ModelSerializer):
class Meta:
model = warning
exclude=()