1

I have two apps peaceout and food. peaceout has a model User and I have imported User in food model. and I am getting the following error when I am running 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'

My model class where I am using User model is

class Order(models.Model):
    itemDict = models.CharField(max_length=200,blank=True)
    user = models.Model(User)
    cost = models.IntegerField(default=0)
    slot = models.Model(OrderSlot)
    order_date = models.DateTimeField(default=datetime.now)

    def __str__(self):
        return self.user.name

Here is my Food Models.py and here is my Peaceout Models.py

1
  • 2
    You link modes with models.ForeignKey, not models.Model. Commented Mar 26, 2016 at 15:21

1 Answer 1

3

The problem is in the way you define the relation to the User model:

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

If you want Order to have a link to a user who placed it, use ForeignKey field:

user = models.ForeignKey(User)

Check the "slot" model also. Same problem.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.