我正在尝试使用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,而不是保存序列化程序?
由于