如何在django rest框架mongoengine中使用序列化器进行upsert

时间:2016-10-04 06:47:07

标签: python mongodb django-rest-framework mongoengine serializer

我正在尝试使用upsert

中的serializer来完成django-rest-framework-mongoengine功能

这是我的代码:

模型

class SocialAccount(Document):
    uid = StringField(max_length=60, required=True)
    platform = StringField(max_length=20, required=True, choices=('facebook','twitter','youtube'))
    created_at = DateTimeField(default=datetime.now(), required=True)

    meta = {
      'collection': 'social_accounts'
    }

串行

class SocialAccountCreateSerializer(DocumentSerializer):
    class Meta:
        model = SocialAccount
        fields = [
            'id',
            'uid',
            'platform'
        ]

查看

class SocialAccountCreateAPIView(CreateAPIView):
    queryset = SocialAccount.objects.all()
    serializer_class = SocialAccountCreateSerializer

    def perform_create(self, serializer):
        serializer.save(app_id=self.request.auth)

如何使用序列化程序进行upsert或使用序列化数据执行upsert,而不是保存序列化程序?

由于

0 个答案:

没有答案