Django序列化到JSON错误:'MetaDict'对象没有属性'concrete_model' [英] Django serialization to JSON error: 'MetaDict' object has no attribute 'concrete_model'
问题描述
我正在使用一个使用Django和MongoDB(作为模型)的应用程序。我正在尝试使用从表单获得的数据来初始化(手动)模型对象(以便将其进一步发送到另一个服务器)。模型如下所示:
class MyModel(DynamicDocument):
study_name = StringField(default =first study )
individual_name = StringField(default =individual)
file_list = ListField(StringField)#这是某些文件的路径列表
以我所做的以下形式:
pilot_object = MyModel ()
pilot_object.individual_name = self.data ['individual_name']
pilot_object.study_name = self.data ['study_name']
pilot_object.file_list = files_list #file路径(字符串)
其中self.data是从表单接收的数据。
现在我想按照文档中的描述序列化JSON对象(pilot_object):
data_serialized = serializers。序列化('json',[pilot_object,])
但是我收到这个错误:
'MetaDict'对象没有属性'concrete_model'
,序列化失败。 p>
任何人都可以帮忙?
如果你有meta {继承:True }然后删除它。它正在寻找具体的类,我认为你没有设计,所以不需要继承是无论如何。它为我工作。
I am working on an application that uses Django and MongoDB (as a model). I am trying to initialize (by hand) a model object (in order to send it further to another server), using the data got from a form. The model looks like this:
class MyModel(DynamicDocument):
study_name = StringField(default="first study")
individual_name = StringField(default="individual")
file_list = ListField(StringField) # this is a list of paths to some files
In the form I am doing the following:
pilot_object = MyModel()
pilot_object.individual_name = self.data['individual_name']
pilot_object.study_name = self.data['study_name']
pilot_object.file_list = files_list #file paths (strings)
where self.data is the data received from the form. Now I want to serialize to JSON this object (pilot_object) as described in the documentation:
data_serialized = serializers.serialize('json', [pilot_object, ])
but I get this error:
'MetaDict' object has no attribute 'concrete_model'
and the serialization fails.
Can anyone help?
If you have meta{Inheritance:True} then remove it. It is looking for concrete class which i think you havent designed so no need for inheritance to be True anyhow. It worked for me.
这篇关于Django序列化到JSON错误:'MetaDict'对象没有属性'concrete_model'的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!