DRF序列化程序不更新选择字段值?

时间:2018-02-08 11:12:46

标签: django-rest-framework python-3.6

class ReportSerializer(serializers.ModelSerializer):
    class Meta:
        model = ReportCreationData
        fields = ('url', 'id', 'connection_name', 'query_json', 'query_name', 'subject', 'mail_body',
          'table', 'connection_id')


class AssignReportsSerializer(serializers.HyperlinkedModelSerializer):
    def __init__(self, *args, **kwargs):
        report_queryset = ReportCreationData.objects.all()
        choices = [(t.query_name,t.query_name) for t in report_queryset]
        self.fields['query_name'].choices = choices
        super(AssignReportsSerializer, self).__init__(*args, **kwargs)

    class Meta:
        model = AssignReportsData
        fields = ('url', 'id', 'report_creation_data_id', 'username', 'email', 'active', 'channel',
                  'query_name', 'condition')

Problem is whenever  ReportSerializer attribute query name is updated then this updated does not populated in choice field of AssignReportsSerializer.

将一个序列化程序的属性填充到另一个序列化程序的最佳方法是什么?

Problem is whenever  ReportSerializer attribute query name is updated then this updated does not populated in choice field of AssignReportsSerializer.

将一个序列化程序的属性填充到另一个序列化程序的最佳方法是什么     问题是只要更新了ReportSerializer属性查询名称,就会在AssignReportsSerializer的选择字段中填充此更新。

将一个序列化程序的属性填充到另一个序列化程序的最佳方法是什么

0 个答案:

没有答案