我的模特:
class news_ids(models.Model):
status = StatusField()
class news_headlines(models.Model):
newsId = models.ForeignKey(news_ids, related_name = 'news', on_delete=models.CASCADE)
lang_code=LanguageField()
headline=models.CharField(max_length=100,unique=True)
我的序列化器:
class NewsSerializer(QueryFieldsMixin,serializers.ModelSerializer):
class Meta:
model=news_headlines
fields=('lang_code','headline')
class NewsIDSerializer(QueryFieldsMixin,serializers.ModelSerializer):
news = NewsSerializer(many=True)
class Meta:
model = news_ids
fields = ('id','news','status','default_language')
def create(self, validated_data):
"""Create function to post the data"""
def update(self, instance, validated_data):
""" Update function to put/patch the data"""
如何在Django中实现这一目标?