Django AttributeError:'Model'对象没有属性'_meta'

时间:2016-03-26 15:11:32

标签: python django django-models

我有两个应用@Override public void write(XmlSerializer writer) throws IOException { Log.d("DEBUG", "XML create process started"); env = "http://schemas.xmlsoap.org/soap/envelope/"; String tem = "http://tempuri.org/"; String ner = "http://schemas.datacontract.org/2004/07/MYSERVICE"; //writer.text("<?xml version=\"1.0\" encoding=\"UTF-8\"?>"); // Don't try like above, it will cause errors, for instead of this, you should use below code writer.startDocument("UTF-8", true); writer.setPrefix("soapenv", env); //these are propably same for you writer.setPrefix("tem", tem); //these are propably same for you writer.setPrefix("ner", ner); // but this must change with your namespace writer.setPrefix("myTag", ner); writer.startTag(env, "Envelope"); writer.startTag(env, "Header"); writeHeader(writer); writer.endTag(env, "Header"); writer.startTag(env, "Body"); writer.startTag(tem, "Method"); writer.startTag(tem, "inputObject"); writer.startTag(ner, "property"); writer.text("property value"); writer.endTag(ner, "property"); writeBody(writer); writer.endTag(tem, "inputObject"); writer.endTag(tem, "Method"); writer.endTag(env, "Body"); writer.endTag(env, "Envelope"); writer.endDocument(); Log.d("DEBUG","XML created"); } peaceoutfood有一个模型peaceout,我在User模型中导入了User。 当我运行food

时,我收到以下错误
python manage.py syncdb

我使用 Traceback (most recent call last): File "manage.py", line 10, in <module> execute_from_command_line(sys.argv) File "/Users/madhu/Documents/django/my_project/venv/lib/python2.7/site-packages/django/core/management/__init__.py", line 354, in execute_from_command_line utility.execute() File "/Users/madhu/Documents/django/my_project/venv/lib/python2.7/site-packages/django/core/management/__init__.py", line 328, in execute django.setup() File "/Users/madhu/Documents/django/my_project/venv/lib/python2.7/site-packages/django/__init__.py", line 18, in setup apps.populate(settings.INSTALLED_APPS) File "/Users/madhu/Documents/django/my_project/venv/lib/python2.7/site-packages/django/apps/registry.py", line 108, in populate app_config.import_models(all_models) File "/Users/madhu/Documents/django/my_project/venv/lib/python2.7/site-packages/django/apps/config.py", line 198, in import_models self.models_module = import_module(models_module_name) File "/usr/local/Cellar/python/2.7.11/Frameworks/Python.framework/Versions/2.7/lib/python2.7/importlib/__init__.py", line 37, in import_module __import__(name) File "/Users/madhu/Documents/django/my_project/pps/food/models.py", line 37, in <module> class Order(models.Model): File "/Users/madhu/Documents/django/my_project/pps/food/models.py", line 39, in Order user = models.Model(User) File "/Users/madhu/Documents/django/my_project/venv/lib/python2.7/site-packages/django/db/models/base.py", line 399, in __init__ if args_len > len(self._meta.concrete_fields): AttributeError: 'Model' object has no attribute '_meta' 模型的模型类是

User

这是我的webstrous 这是我的Food Models.py

1 个答案:

答案 0 :(得分:2)

问题在于您定义与User模型的关系的方式:

class Order(models.Model):
    itemDict = models.CharField(max_length=200,blank=True)
    user = models.Model(User)  # <- HERE 

如果您希望Order有一个指向放置该用户的用户的链接,请使用ForeignKey field

user = models.ForeignKey(User)

也检查“插槽”模型。同样的问题。