from django.db import models
# Create your models here.
class Post(models.Model):
text = models.TextField()
def __str__(self):
return self.text[:50]
POWER_CHOICES= (('O', 'ON'),
('F','OFF')
STATE_CHOICES =(('AV','Available'),
('U','In Use '),
('NU','Do Not Use')
class Device(models.Model):
name = models.CharField(unique=True,max_length=50 )
ipaddress=models.ForeignKey('Ipaddress', on_delete=models.CASCADE,)
devicetype= models.ForeignKey('DeviceType', on_delete=models.CASCADE)
model= models.ForeignKey('DeviceModel', on_delete=models.CASCADE)
description= models.TextField(max_length=400)
location= models.ForeignKey('Location', on_delete=models.CASCADE)
group= models.ForeignKey('DeviceGroup', on_delete=models.CASCADE)
managment= models.CharField(max_length=100)
power= models.CharField(max_length=6, choices=POWER_CHOICES)
offtime= models.CharField(max_length=30)
state= models.CharField(max_length=10, choices=STATE_CHOICES)
user= models.CharField(max_length=100)
# department= models.ForeignKey('Department',on_delete=models.CASCADE)
comments= models.CharField(max_length=200)
def __unicode__(self):
return self.name[:50]
class DeviceType(models.Model):
name= models.CharField(max_length=100, unique=True)
def __unicode__(self):
return self.name[:50]
class DeviceModel(models.Model):
name= models.CharField(max_length=100, unique=True)
def __unicode__(self):
return self.name[:50]
class Ipaddress(models.Model):
address=models.CharField(max_length=20, unique=True)
owner=models.CharField(max_length=200)
loation=models.CharField(max_length=200)
note =models.TextField()
def __unicode__(self):
return self.address[:50]
class Department:
name= models.CharField(max_length=100, unique=True)
def __unicode__(self):
return self.name[:50]
class DeviceGroup:
name= models.CharField(max_length=100, unique=True)
def __unicode__(self):
return self.name[:50]
class Location:
description= models.CharField(max_length=100, unique=True)
def __unicode__(self):
return self.description[:50]
我的管理页面如下所示:
代码语言:
javascript
复制
from django.contrib import admin
from pages.models import Post, Device, DeviceType, DeviceModel, Ipaddress, DeviceGroup, Location
admin.site.register(Post)
admin.site.register(Device)
admin.site.register(DeviceType)
admin.site.register(DeviceModel)
admin.site.register(Ipaddress)
#admin.site.register(Department)
admin.site.register(DeviceGroup)
admin.site.register(Location)
我看到了后面的错误,不知道是什么导致了这个错误。有人能告诉我一些想法吗。请
代码语言:
javascript
复制
...
File "C:\Users\mohiuddin_rana\labmcproject\pages\admin.py", line 10, in <module>
admin.site.register(DeviceGroup)
File "C:\Users\mohiuddin_rana\AppData\Local\Programs\Python\Python37-32\lib\site-packages\django\contrib\admin\sites.py", line 102, in register
for model in model_or_iterable:
TypeError: 'type' object is not iterable