customizing admin of django to have dependent select fields(自定义 django 的管理员以具有依赖的选择字段)
问题描述
I am new in django , I am developing admin panel first for my site. I need to have dependent select fields, so that after selecting country, user will be able to select city. I want that when I select country then cities of that country options load in city select box but I don't know how to customize django admin. I have done so in JS, using AJAX and PHP. So I know how to do it manually but don't know how to use ajax in django and how to customize it.
On some other questions I read that one should read, django documentation, so I tried to read and find at admin documentation but couldn't found way to customize django admin panel. Do I need to customize full page for those select boxes? Or please tell that how can I add some jquery code to it so that I can do it via JS?
You probably want to use the feature Grouped Selects in django smart selects. From the README:
If you have the following model:
class Location(models.Model)
continent = models.ForeignKey(Continent)
country = models.ForeignKey(Country)
And you want that all countries are grouped by the Continent and that Groups are used in the select change to the following:
from smart_selects.db_fields import GroupedForeignKey
class Location(models.Model)
continent = models.ForeignKey(Continent)
country = GroupedForeignKey(Country, "continent")
这篇关于自定义 django 的管理员以具有依赖的选择字段的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:自定义 django 的管理员以具有依赖的选择字段


基础教程推荐
- 使 Python 脚本在 Windows 上运行而不指定“.py";延期 2022-01-01
- 哪些 Python 包提供独立的事件系统? 2022-01-01
- 如何在Python中绘制多元函数? 2022-01-01
- 使用 Google App Engine (Python) 将文件上传到 Google Cloud Storage 2022-01-01
- 症状类型错误:无法确定关系的真值 2022-01-01
- 将 YAML 文件转换为 python dict 2022-01-01
- Python 的 List 是如何实现的? 2022-01-01
- 如何在 Python 中检测文件是否为二进制(非文本)文 2022-01-01
- 合并具有多索引的两个数据帧 2022-01-01
- 使用Python匹配Stata加权xtil命令的确定方法? 2022-01-01