根据djnago中的字段值对特定对象进行反序列化

现在我有一个对象模型:

class Report(models.Model):
    TYPE1 = 'type1'
    TYPE2 = 'type2'
    TYPES_CHOICES = [
        (TYPE1,'type1'),(TYPE2,'type2'),]

    name = models.CharField(max_length=255)
    type = models.CharField(max_length=20,choices=TYPES_CHOICES)

和与此模型相对应的ModelSerializer:

class ReportSerializer(serializers.ModelSerializer):
    class Meta:
        model = Report
        depth = 1
        fields = ('name','type')

基于type的值,我想创建Type1ReportType2Report(它们将以其他方式实现某些方法)。但是Type1ReportType2Report应该都保存在同一数据库表中。

是否有一种使用DRF序列化器而又没有遍历的方法?

如果没有这种方法,那么最佳做法是什么?

baihe703 回答:根据djnago中的字段值对特定对象进行反序列化

暂时没有好的解决方案,如果你有好的解决方案,请发邮件至:iooj@foxmail.com
本文链接:https://www.f2er.com/3117948.html

大家都在问