Skip to content

Commit abfadc1

Browse files
committed
add more code examples including SimpleListFilter for django
1 parent 40b7974 commit abfadc1

File tree

5 files changed

+94
-5
lines changed

5 files changed

+94
-5
lines changed

content/pages/examples/django/django-conf-urls-url.markdown

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -266,3 +266,34 @@ urlpatterns.extend([
266266
```
267267

268268

269+
## Example 6 from apiserver
270+
[apiserver](https://github.com/renjith-tring/apiserver) is a
271+
[RESTful web API](/application-programming-interfaces.html) server project
272+
built with [Django](/django.html) for user management tasks such as
273+
registration (with email verification), login, logout and password changes.
274+
275+
[**apiserver / apps / accounts / urls.py**](https://github.com/renjith-tring/apiserver/blob/master/apps/accounts/urls.py)
276+
277+
```python
278+
~~from django.conf.urls import url, include
279+
from tastypie.api import Api
280+
from apps.accounts.api import UserResource
281+
from apps.accounts import signals
282+
283+
v1_api = Api(api_name='v1')
284+
v1_api.register(UserResource())
285+
286+
urlpatterns = [
287+
~~ url(r'^api/', include(v1_api.urls)),
288+
~~ url(r'^reset/(?P<uidb36>[0-9A-Za-z_\-]+)/' + \
289+
~~ '(?P<token>[0-9A-Za-z]{1,13}-[0-9A-Za-z]{1,20})/$',
290+
~~ 'reset_confirm',
291+
~~ name='password_reset_confirm'
292+
~~ ),
293+
294+
~~ url(r'^accounts/password/reset/' + \
295+
~~ '(?P<uidb64>[0-9A-Za-z]+)-(?P<token>.+)/$',
296+
~~ 'django.contrib.auth.views.password_reset_confirm',
297+
~~ {'post_reset_redirect': '/accounts/password/done/'},),
298+
]
299+
```
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
title: django.contrib.admin.filters SimpleListFilter Example Code
2+
category: page
3+
slug: django-contrib-admin-filters-simplelistfilter-examples
4+
sortorder: 50055
5+
toc: False
6+
sidebartitle: django.contrib.admin.filters SimpleListFilter
7+
meta: Python code examples for using the SimpleListFilter class contained within django.contrib.admin.filters.
8+
9+
10+
[SimpleListFilter](https://github.com/django/django/blob/master/django/contrib/admin/filters.py)
11+
is a class within the [Django](/django.html) project which can
12+
be subclasses to customize the Django admin's lookups and querying
13+
interface.
14+
15+
Understanding the following concepts are useful when coding projects
16+
that use Django's `SimpleListFilter` class:
17+
18+
* [Django](/django.html) and [Django templates](/django-templates.html)
19+
* [Web development](/web-development.html),
20+
[web frameworks](/web-frameworks.html) and
21+
[HTML](/hypertext-markup-language-html.html)
22+
* [Angular](/angular.html) and [JavaScript](/javascript.html)
23+
24+
You can also view the [complete all topics page](/table-of-contents.html)
25+
for even more resources.
26+
27+
28+
## Example 1 from AuditLog
29+
[Auditlog](https://github.com/jjkester/django-auditlog)
30+
([project documentation](https://django-auditlog.readthedocs.io/en/latest/))
31+
is a [Django](/django.html) app that logs changes to Python objects,
32+
similar to the Django admin's logs but with more details and
33+
output formats. Auditlog's source code is provided as open source under the
34+
[MIT license](https://github.com/jjkester/django-auditlog/blob/master/LICENSE).
35+
36+
[**django-auditlog / src / auditlog / filters.py**](https://github.com/jjkester/django-auditlog/blob/master/src/auditlog/filters.py)
37+
38+
```python
39+
# filters.py
40+
~~from django.contrib.admin import SimpleListFilter
41+
42+
43+
~~class ResourceTypeFilter(SimpleListFilter):
44+
title = 'Resource Type'
45+
parameter_name = 'resource_type'
46+
47+
def lookups(self, request, model_admin):
48+
qs = model_admin.get_queryset(request)
49+
types = qs.values_list('content_type_id', 'content_type__model')
50+
return list(types.order_by('content_type__model').distinct())
51+
52+
def queryset(self, request, queryset):
53+
if self.value() is None:
54+
return queryset
55+
return queryset.filter(content_type_id=self.value())
56+
```

content/pages/examples/django/django-core-mail-send-mail.markdown

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ class.
1515

1616
## Example 1 from apiserver
1717
[apiserver](https://github.com/renjith-tring/apiserver) is a
18-
[RESTful web API](/application-programming-interfaces.html) project
18+
[RESTful web API](/application-programming-interfaces.html) server project
1919
built with [Django](/django.html) for user management tasks such as
2020
registration (with email verification), login, logout and password changes.
2121

content/pages/examples/django/django-utils-html-format-html.markdown

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,8 @@ that use Django's `format_html` function:
2222
[HTML](/hypertext-markup-language-html.html)
2323
* [Angular](/angular.html) and [JavaScript](/javascript.html)
2424

25-
You should also view the [extensive all topics page](/table-of-contents.html)
26-
for additional resources.
25+
You can also view the [complete all topics page](/table-of-contents.html)
26+
for even more resources.
2727

2828

2929
## Example 1 from django-angular
@@ -160,12 +160,13 @@ def djng_locale_script(context, default_language='en'):
160160
```
161161

162162

163-
## Example 2 from django-auditlog
163+
## Example 2 from AuditLog
164164
[Auditlog](https://github.com/jjkester/django-auditlog)
165165
([project documentation](https://django-auditlog.readthedocs.io/en/latest/))
166166
is a [Django](/django.html) app that logs changes to Python objects,
167167
similar to the Django admin's logs but with more details and
168-
output formats.
168+
output formats. Auditlog's source code is provided as open source under the
169+
[MIT license](https://github.com/jjkester/django-auditlog/blob/master/LICENSE).
169170

170171
[**django-auditlog / src / auditlog / mixins.py**](https://github.com/jjkester/django-auditlog/blob/master/src/auditlog/mixins.py)
171172

theme/templates/table-of-contents.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -232,6 +232,7 @@ <h3 style="margin-top:16px">Django examples</h3>
232232
<h4 class="bp"><a href="/django-conf-settings-examples.html">django.conf.settings</a></h4>
233233
<h4 class="bp"><a href="/django-conf-urls-url-examples.html">django.conf.urls.url</a></h4>
234234
<h4 class="bp"><a href="/django-contrib-admin-examples.html">django.contrib.admin</a></h4>
235+
<h4 class="bp"><a href="/django-contrib-admin-filters-simplelistfilter-examples.html">django.contrib.admin.filters SimpleListFilter</a></h4>
235236
<h4 class="bp"><a href="/django-core-mail-send-mail-examples.html">django.core.mail.send_mail</a></h4>
236237
<h4 class="bp"><a href="/django-core-mail-messages-emailmessage-examples.html">django.core.mail.messages EmailMessage</a></h4>
237238
<h4 class="bp"><a href="/django-core-management-base-basecommand-examples.html">django.core.management.base BaseCommand</a></h4>

0 commit comments

Comments
 (0)