我的django-smart_selects有问题:
型号:
class Demande_Expertise(models.Model):
user = models.ForeignKey(User)
material = models.ForeignKey("Material")
categorie = ChainedForeignKey("Category",
chained_field="material",
chained_model_field="name",
show_all=False,
auto_choose=True)
droits_acces = models.CharField(_('val_champ'), max_length=150, choices = DROITS)
groupe = models.ForeignKey(Group, blank = True, null= True, default = None)
etat = models.CharField(_('val_champ'), max_length=150, choices = ETAT, default = '2')
class Category(models.Model):
name = models.CharField(_('name'), max_length=50)
slug = models.SlugField()
expert = models.ForeignKey(Expert, null=True, blank=True, default = None)
description = models.TextField(_('description'), blank=True)
class Material(models.Model):
name = models.CharField(_('name'), max_length=50)
description = models.TextField(_('description'), blank=True)
slug = models.SlugField()
category = models.ForeignKey(Category, verbose_name=_('category'))
created = models.DateField(_("creation date"), auto_now_add=True)
我收到错误
Exception Type: ValueError
Exception Value: need more than 1 value to unpack
File "C:\03_08\monprojet\..\monprojet\material\models.py", line 48, in Demande
_Expertise
auto_choose=True)
File "build\bdist.win32\egg\smart_selects\db_fields.py", line 20, in __init__
ValueError: need more than 1 value to unpack
这意味着什么?
答案 0 :(得分:0)
根据the source code of django-smart-select。执行以下。
self.app_name, self.model_name = to.split('.')
to
是您传递的型号名称。
>>> app_name, model_name = "Category".split('.')
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ValueError: need more than 1 value to unpack
>>> app_name, model_name = "app_name.Category".split('.')
>>>
>>> a, b = ['a', 'b']
>>> a, b = ['a']
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ValueError: need more than 1 value to unpack
您需要将模型名称作为app_name.model_name
的形式传递。
categorie = ChainedForeignKey("material.Category",
....)