处理链接模型字段的django应用程序。

django-smart-selects的Python项目详细描述


#django smart选择

[![构建状态](https://travis-ci.org/digi604/django-smart-selects.svg?branch=master)(https://travis ci.org/digi604/django smart selects)

[![覆盖状态](https://coveralls.io/repos/github/digi604/django-smart-selects/badge.svg?branch=master)(https://coveralls.io/github/digi604/django-smart-selects?branch=master)



此包允许您通过向模型添加自定义外键或多对多字段来快速筛选或分组"链式"模型。这将使用ajax查询仅加载适用的链接对象。

**警告**:ajax端点默认情况下不强制执行任何权限。这意味着**任何带有链接字段的模型都是世界可读的**。如果您希望对此权限进行更多控制,[`django autocomplete light`](https://github.com/yourlabs/django-autocomplete-light)包是一个很好的高质量包,可以通过权限检查启用相同的功能。

模型:

`` python
类大陆(models.model):
name=models.charfield(max_length=255)

class country(models.model):
大陆=models.foreignkey(contin)
name=models.charfield(max_length=255)

类位置(models.model):
continent=models.foreignkey(大陆)
country=models.foreignkey(国家)
area=models.foreignkey(地区)
city=models.charfield(最大长度=50)
street=models.charfield(最大长度=100)
````

一旦选择了一个大陆,如果您只想要该大陆上的国家大陆要可用,您可以在'location'模型上使用'chainedforeignkey':

``python
from smart\selects.db\u fields import chainedforeignkey


class location(models.model)
contain=models.foreignkey(大陆)
country=chainedforeignkey(
country,
链式字段=大陆,
链式字段=大陆,
全部显示=假,
自动选择=真,
排序=真)
区域=外键(区域)
城市=模型.charfield(最大长度=50)
街道=模型.charfield(最大长度=100)
```

在"contain"、"country"和"location"示例中,"chained"字段是model"location"中字段"contain"的名称。

``python
class location(models.model)
contain=models.foreignkey(contain)
```

d_model_field`表示链接模型的字段,该字段对应于由'chained_field'链接的模型。在"contain"、"country"和"location"示例中,"chained\u model\u field"是"country"模型中"contain"字段的名称。

``python
class country(models.model):
contain=models.foreignkey(contain)
```

如果只应显示筛选的结果,或者还想进一步向下显示其他结果。


测试结果集是否应按字典顺序排序。如果要使用"model.ordering"选项,请禁用。默认为"true"。





类编写器(models.model):
名称=models.charfield(最大长度=255)
出版物=models.manytomanyfield('publication',blank=true,null=true)

charfield(最大长度=255)
```



相反,只需将"horizontal=true"传递给"chainedmanytomanyfield":

``python
from smart-selects.db-fields import chainedmanytomanyfield


class publication(models.model):
name=models.charfield(max-length=255)


class writer(models.model):
name=models.charfield(最大长度=255)
publications=models.manytomanyfield('publication',blank=true,null=true)


类书(models.model):
publication=models.foreignkey(publication)
writer=chainedmanytomanyfield(
writer,
horizontal=true,

name="writer"
chained_field="publication"
chained_model_field="publications"
name=models.charfield(max_len长=255)
```






<
\chainedmanytomanyfield-chainedmanyfield选项






指示灯是应链接到的同一模型上的字段。在"publication"、"writer"和"book"示例中,"chained\u field"是model"book"中字段"publication"的名称。

``python
类书(models.model):
publication=models.foreignkey(publication)
````

_model_field表示链接模型的字段,该字段对应于由"chained_field"链接的模型。在"publication"、"writer"、"book"示例中,"chained_model_field"是"writer"模型中"publications"字段的名称。

``python
`class writer(models.model):
publications=models.manytomanyfield('publication',blank=true,null=true)
```

`auto choose`(操作可选)

`auto_choose`指示只有一个可用选项时是否自动选择该选项。


`水平`(可选)


您有以下模型:

``python
class country(models.model):
contain=models.foreignkey(contain)


class location(models.model):
contain=models.foreignkey(contain)
country=models.foreignkey(country)
```

在HTML选择列表中按国家/地区分组,您可以使用"groupedforeignkey":

``python
from smart\selects.db\u fields import groupedforeignkey


class location(models.model):
contain=models.foreignkey(contain)
count=groupedforeignkey(country,"大陆")
````



将"smart_selects"添加到"installed_apps"中
2。将"smart\u selects"url添加到项目的"url.py"中。这对于"链式选择"和"链式多个选择"是必需的。例如:

`` python
url patterns=patterns('',
url(r'^admin/',include(admin.site.urls)),
url(r'^chaining/',include('smart_selects.urls'),
```

3。您还需要将jquery包含在每个页面中,其中包含来自"smart戋u selects"的字段,或者在项目的"settings.py"中设置"jquery戋url=true"。




如果您希望
使用其他版本,请将完整的url放在此处。设置'jquery_url=false`
以完全禁用加载jquery。

`use_django_jquery`
:默认情况下,`smart_selects从google的cdn加载jquery。但是,它可以使用django的
管理区域中的jquery。设置"use_django_jquery=true"以启用此行为。




东南方

欢迎加入QQ群-->: 979659372 Python中文网_新手群

推荐PyPI第三方库


热门话题
java Android同步不同页面上的按钮   java评测每个类收集的垃圾对象实例数   java(Spring MVC+Hibernate 4+Test 4)自动连线DAO返回NULL   java Android编辑文本和虚拟键盘   java Selenium与BrowserMobProxy   JAVAlang.NoClassDefFoundError:com/sun/jersey/spi/inject/Errors$关闭原因?   java为什么在我成功登录后仍然会出现“不正确的帐户或密码或用户类型”   安卓应用程序在重新启动java时崩溃。网UnknownHostException:无法解析主机   多线程在Java中同步共享静态对象的正确方法是什么?   未调用自定义注释的java类验证(约束类)   java如何将指定目录的存档文件放入所需位置?   java如何识别Selenium中的每个编辑文本字段,如果它们的Xpath都相同   使用gwtmockito/mockito的java简单单选按钮单元测试?