我尝试使用链式选择(智能选择),它适用于管理面板,但不适用于模板(html)。
设置:
JQUERY_URL = False
USE_JQUERY_DJANGO = True
<head>
<meta charset="UTF-8">
<meta name="viewport"
content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>{% block title%}{% endblock %}</title>
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.5.2/css/bootstrap.min.css">
<link rel="stylesheet" href="{% static 'main/css/main.css'%}">
<link rel="stylesheet" href="https://use.fontawesome.com/releases/v5.8.2/css/all.css">
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
<script src="{% static 'smart-selects/admin/js/bindfields.js' %}"></script>
<script src="{% static 'smart-selects/admin/js/chainedfk.js' %}"></script>
<script src="{% static 'smart-selects/admin/js/chainedm2m.js' %}"></script>
</head>
</p>
class Tasks(models.Model):
type = models.ForeignKey(TypeServices,on_delete=models.CASCADE,default='0')
site = ChainedForeignKey(
Services,
chained_field="type",
chained_model_field="type",
show_all=False,
sort=True)