'NoneType' object is not subscriptable in using django smart selects
from django.db import models from django.core.urlresolvers import reverse from django.utils import timezone from smart_selects.db_fields import ChainedForeignKey, ChainedManyToManyField, GroupedForeignKey # Create your models here. #DIRECTOR class director(models.Model): sex = ( ('M', 'Male'), ('F', 'Female'), ) percent = ( ('1', 1), ('2', 2), ('3', 3), ) stats = ( ('Single', 'Single'), ('Married', 'Maried'), ('Separated', 'Separated'), ('Widowed', 'Widowed'), ) firstname = models.CharField(max_length=30, blank = False) lastname = models.CharField(max_length=30, blank = False) middlename = models.CharField(max_length=30, blank = True) birthdate = models.DateField(blank = False) age = models.IntegerField(blank = False) contact = models.CharField(blank = False, max_length=11, default="") email = models.CharField(blank = False, max_length=30, default="") civil_status = models.CharField(max_length=20, default="", choices = stats, blank = False) gender = models.CharField(max_length=1, choices = sex, blank = False) lot_no = models.CharField(max_length=10, blank = False) block_no = models.CharField(max_length=20, blank = False) street = models.CharField(max_length=20, blank = False) brgy = models.CharField(max_length=30, blank =False, default="") city = models.CharField(max_length=30, blank = False) region = models.CharField(max_length=50, blank = False) commission = models.CharField(max_length=1, choices = percent) #def get_absolute_url(self): # return reverse('viewname', kwargs={'pk': self.pk}) def __str__(self): return self.firstname + ' ' + self.middlename + ' ' + self.lastname #MANAGER class manager(models.Model): sex = ( ('M', 'Male'), ('F', 'Female'), ) percent = ( ('1', 1), ('2', 2), ('3', 3), ) stats = ( ('Single', 'Single'), ('Married', 'Maried'), ('Separated', 'Separated'), ('Widowed', 'Widowed'), ) director_name = models.ForeignKey(director) firstname = models.CharField(max_length=30, blank = False) lastname = models.CharField(max_length=30, blank = False) middlename = models.CharField(max_length=30, blank = True) birthdate = models.DateField(blank = False) age = models.IntegerField(blank = False) contact = models.CharField(blank = False, max_length=11, default="") email = models.CharField(blank = False, max_length=30, default="") civil_status = models.CharField(max_length=10, default="", choices = stats, blank = False) gender = models.CharField(max_length=1, choices = sex, blank = False) lot_no = models.CharField(max_length=20, blank = False) block_no = models.CharField(max_length=10, blank = False) street = models.CharField(max_length=20, blank = False) brgy = models.CharField(max_length=30, blank =False, default="") city = models.CharField(max_length=30, blank = False) region = models.CharField(max_length=50, blank = False) commission = models.CharField(max_length=1, choices = percent, blank = False) def __str__(self): return self.firstname + ' ' + self.middlename + ' ' + self.lastname '''return "%s (%s)" % ( self.firstname + ' ' + self.middlename + ' ' + self.lastname, ", ".join(director.firstname + ' ' + director.middlename + ' ' + director.lastname for director in self.director_name.all()) )''' #ASSOCIATE class associate(models.Model): sex = ( ('M', 'Male'), ('F', 'Female'), ) percent = ( ('1', 1), ('2', 2), ('3', 3), ) stats = ( ('Single', 'Single'), ('Married', 'Maried'), ('Separated', 'Separated'), ('Widowed', 'Widowed'), ) #area = ChainedForeignKey(Area, chained_field="country", chained_model_field="country") director_name = models.ForeignKey(director) #manager_name = models.ForeignKey(manager, blank = False) manager_name = ChainedForeignKey( manager, chained_field="director_name", chained_model_field="director_name", show_all=False, auto_choose=True ) firstname = models.CharField(max_length=30, blank = False) lastname = models.CharField(max_length=30, blank = False) middlename = models.CharField(max_length=30, blank = True) birthdate = models.DateField(blank = False) age = models.IntegerField(blank = False) contact = models.CharField(blank = False, max_length=11, default="") email = models.CharField(blank = False, max_length=30, default="") civil_status = models.CharField(max_length=20, default="", choices = stats, blank = False) gender = models.CharField(max_length=1, choices = sex, blank = False) lot_no = models.CharField(max_length=10, blank = False) block_no = models.CharField(max_length=20, blank = False) street = models.CharField(max_length=20, blank = False) brgy = models.CharField(max_length=30, blank =False, default="") city = models.CharField(max_length=30, blank = False) region = models.CharField(max_length=50, blank = False) commission = models.CharField(max_length=1, choices = percent, blank = False) def __str__(self): #return self.firstname + ' ' + self.middlename + ' ' + self.lastname return "%s (%s)" % ( self.firstname + ' ' + self.middlename + ' ' + self.lastname, ", ".join(director.firstname + ' ' + director.middlename + ' ' + director.lastname for director in self.director_name.all()), ", ".join(manager.firstname + ' ' + manager.middlename + ' ' + manager.lastname for manager in self.manager_name.all()), )
在这里输入图像描述
链接地址: http://www.djcxy.com/p/56514.html上一篇: 冲突的模板标签