So I'm trying to set up my django app and I want to link multiple tables each with a unique key identifier. To test this i have the following models. py
from django.db import models
# Create your models here.
class Customer(models.Model):
NAME = models.CharField(max_length=200)
WEBSITE = models.CharField(max_length=200)
PHONE = models.CharField(max_length=200)
EMAIL = models.CharField(max_length=200)
ADDRESS = models.CharField(max_length=200)
VMIDS = models.CharField(max_length=200)
def __unicode__(self):
return self.NAME
# return self.NAME
class Vms(models.Model):
VMID = models.CharField(max_length=200)
VMNAME = models.CharField(max_length=200)
VMSTATUS = models.CharField(max_length=200)
CUSTOMERID = models.ForeignKey(Customer)
def __unicode__(self):
return self.VMNAME
class Vmspecs(models.Model):
CPUS = models.CharField(max_length=200)
CORES = models.CharField(max_length=200)
MEMORY = models.CharField(max_length=200)
HDSPACE = models.CharField(max_length=200)
OS = models.CharField(max_length=200)
UPTIME = models.CharField(max_length=200)
VMID = models.ForeignKey(Vms)
def __unicode__(self):
return self.VMID
If works fantastic until I try to add a vmspecs in the admin panel and link it to a VM it gives the following error
Environment:
Request Method: POST
Django Version: 1.6.4
Python Version: 2.7.3
Installed Applications:
('django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'vmware')
Installed Middleware:
('django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.common.CommonMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'django.middleware.clickjacking.XFrameOptionsMiddleware')
Traceback:
File "/usr/local/lib/python2.7/dist-packages/django/core/handlers/base.py" in get_response
114. response = wrapped_callback(request, *callback_args, **callback_kwargs)
File "/usr/local/lib/python2.7/dist-packages/django/contrib/admin/options.py" in wrapper
432. return self.admin_site.admin_view(view)(*args, **kwargs)
File "/usr/local/lib/python2.7/dist-packages/django/utils/decorators.py" in _wrapped_view
99. response = view_func(request, *args, **kwargs)
File "/usr/local/lib/python2.7/dist-packages/django/views/decorators/cache.py" in _wrapped_view_func
52. response = view_func(request, *args, **kwargs)
File "/usr/local/lib/python2.7/dist-packages/django/contrib/admin/sites.py" in inner
198. return view(request, *args, **kwargs)
File "/usr/local/lib/python2.7/dist-packages/django/utils/decorators.py" in _wrapper
29. return bound_func(*args, **kwargs)
File "/usr/local/lib/python2.7/dist-packages/django/utils/decorators.py" in _wrapped_view
99. response = view_func(request, *args, **kwargs)
File "/usr/local/lib/python2.7/dist-packages/django/utils/decorators.py" in bound_func
25. return func(self, *args2, **kwargs2)
File "/usr/local/lib/python2.7/dist-packages/django/db/transaction.py" in inner
371. return func(*args, **kwargs)
File "/usr/local/lib/python2.7/dist-packages/django/contrib/admin/options.py" in add_view
1133. self.log_addition(request, new_object)
File "/usr/local/lib/python2.7/dist-packages/django/contrib/admin/options.py" in log_addition
600. action_flag=ADDITION
File "/usr/local/lib/python2.7/dist-packages/django/contrib/admin/models.py" in log_action
19. e = self.model(None, None, user_id, content_type_id, smart_text(object_id), object_repr[:200], action_flag, change_message)
Exception Type: TypeError at /admin/vmware/vmspecs/add/
Exception Value: 'Vms' object has no attribute '__getitem__'