django smart_selects,第二级不会填充 [英] django smart_selects, second level won't populate
问题描述
我无法获得第二个级别(子类别/ E_cat)下拉以填充。第一级(类别)似乎工作正常。我想我已经尝试了chained_field和chained_model_field选择的每一个合理的组合,没有成功。
I can not get the second level (subcategory/E_cat) drop down to populate. First level (Category) seems to be working fine. I think I've tried just about every reasonable combination of chained_field and chained_model_field selections without success.
我希望Equip表填充类别的ID,ID子类别。
I want the Equip table populate with the ID for the category and the ID for the subcategory.
下面是模型当前的样子。我究竟做错了什么?
Below is what the model currently looks like. What am I doing wrong?
model.py
model.py
class Category(models.Model):
cat_no = models.IntegerField(null=True, blank=True)
cat_txt = models.CharField(max_length=45)
def __unicode__(self):
return self.cat_txt
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)
def __unicode__(self):
return self.scat_txt
class Equip(models.Model):
category = models.ForeignKey(Category)
subcategory = ChainedForeignKey(
E_cat,
chained_field="category",
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)
推荐答案
更新 - 2017年5月
包含此标签在jQuery版本2之后。它在Django 1.10和1.11版本中使用python 3.5.2完美地工作。
希望这有助于您
include this tag right after jQuery version 2 . It works perfrectly well in Django 1.10 and 1.11 version using python 3.5.2. Hope this helps you
<script type="text/javascript" src="{% static 'smart-selects/admin/js/chainedfk.js' %}"></script>
<script type="text/javascript" src="{% static 'smart-selects/admin/js/chainedm2m.js' %}"></script>
<script type="text/javascript" src="{% static 'smart-selects/admin/js/bindfields.js' %}"></script>
这篇关于django smart_selects,第二级不会填充的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!