收到错误:
TypeError: init ()得到了一个意外的关键字参数'chained_model_field'
在更改模型后运行syncdb。
model.py
class Category(models.Model):
cat_no = models.IntegerField(null=True, blank=True)
cat_txt = models.CharField(max_length=45)
class E_cat(models.Model):
cat_no = models.ForeignKey(Category)
cat_txt = models.CharField(max_length=45)
scat_no = models.IntegerField(null=True, blank=True)
scat_txt = models.CharField(max_length=45)
class Equip(models.Model):
category = models.ForeignKey(Category)
subcategory = models.ForeignKey(
E_cat,
chained_field="cat_no",
chained_model_field="cat_no",
show_all=False,
auto_choose=True,
)
manufacturer = models.CharField(max_length=35, blank=True)
mfg_no = models.CharField(max_length=35, blank=True)
size = models.CharField(max_length=35, blank=True)
color = models.CharField(max_length=35, blank=True)
quanity = models.IntegerField(null=True, blank=True)
short_description = models.CharField(max_length=80, blank=True)
location_zip = models.IntegerField(null=True, blank=True)
listings = models.ForeignKey(Listings)
info = models.TextField(null=True, blank=True)
答案 0 :(得分:0)
这里的问题是django.db.models.ForeignKeyField
不接受chained_model_field
参数。
您可以在收到的追溯中看到这一点:
File ".../models.py", line 42, in MyModel subcategory = m.ForeignKey(…) <--- here File "…/related.py", line 840, in __init__ Field.__init__(self, **kwargs) TypeError: __init__() got an unexpected keyword argument 'chained_model_field'
您可能希望https://github.com/digi604/django-smart-selects定义类似ForeignKey
的字段,其中包含chained_model_field
参数吗?