Skip to content

Commit 635343e

Browse files
authored
Add reference anchors to filter types to facilitate intersphinx refs (#1706)
* Update filterset.py Remove the template_pack setter on rest_framework cripsy forms. This lets crispy forms decide what the template pack should be. * add reference anchors to filter types in docs to facilitate intersphinx referencing * replace section references with class references * add osx DS_Store and _docs to gitignore * go crazy with interpshinx references
1 parent 7b3176e commit 635343e

File tree

7 files changed

+220
-210
lines changed

7 files changed

+220
-210
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,3 +12,5 @@ docs/_build
1212
.idea
1313
.env
1414
.vscode
15+
_docs
16+
.DS_Store

docs/conf.py

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,9 @@
2828

2929
# Add any Sphinx extension module names here, as strings. They can be extensions
3030
# coming with Sphinx (named 'sphinx.ext.*') or your custom ones.
31-
extensions = []
31+
extensions = [
32+
"sphinx.ext.intersphinx"
33+
]
3234

3335
# Add any paths that contain templates here, relative to this directory.
3436
templates_path = ["_templates"]
@@ -257,3 +259,15 @@
257259

258260
# How to display URL addresses: 'footnote', 'no', or 'inline'.
259261
# texinfo_show_urls = 'footnote'
262+
263+
264+
intersphinx_mapping = {
265+
"django": (
266+
"https://docs.djangoproject.com/en/stable",
267+
"https://docs.djangoproject.com/en/stable/_objects/",
268+
),
269+
"python": ('https://docs.python.org/3', None)
270+
}
271+
272+
# elide module names in class headings
273+
add_module_names = False

docs/guide/usage.txt

Lines changed: 22 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ The filter
2929
----------
3030

3131
We have a number of fields and we want to let our users filter based on the
32-
name, the price or the release_date. We create a ``FilterSet`` for this::
32+
name, the price or the release_date. We create a :class:`~django_filters.filterset.FilterSet` for this::
3333

3434
import django_filters
3535

@@ -41,16 +41,17 @@ name, the price or the release_date. We create a ``FilterSet`` for this::
4141
fields = ['price', 'release_date']
4242

4343

44-
As you can see this uses a very similar API to Django's ``ModelForm``. Just
45-
like with a ``ModelForm`` we can also override filters, or add new ones using a
44+
As you can see this uses a very similar API to Django's :class:`~django.forms.ModelForm`. Just
45+
like with a :class:`~django.forms.ModelForm` we can also override filters, or add new ones using a
4646
declarative syntax.
4747

4848
Declaring filters
4949
~~~~~~~~~~~~~~~~~
5050

5151
The declarative syntax provides you with the most flexibility when creating
5252
filters, however it is fairly verbose. We'll use the below example to outline
53-
the :ref:`core filter arguments <core-arguments>` on a ``FilterSet``::
53+
the :ref:`core filter arguments <core-arguments>` on a :class:`~django_filters.filterset.FilterSet`::
54+
5455

5556
class ProductFilter(django_filters.FilterSet):
5657
price = django_filters.NumberFilter()
@@ -72,18 +73,15 @@ There are two main arguments for filters:
7273
- ``field_name``: The name of the model field to filter on. You can traverse
7374
"relationship paths" using Django's ``__`` syntax to filter fields on a
7475
related model. ex, ``manufacturer__name``.
75-
- ``lookup_expr``: The `field lookup`_ to use when filtering. Django's ``__``
76-
syntax can again be used in order to support lookup transforms.
77-
ex, ``year__gte``.
76+
- ``lookup_expr``: The :ref:`field lookup <django:field-lookups>` to use when filtering.
77+
Django's ``__`` syntax can again be used in order to support lookup transforms. ex, ``year__gte``.
7878

7979
.. _`field lookup`: https://docs.djangoproject.com/en/stable/ref/models/querysets/#field-lookups
8080

8181
Together, the field ``field_name`` and ``lookup_expr`` represent a complete Django
8282
lookup expression. A detailed explanation of lookup expressions is provided in
83-
Django's `lookup reference`_. django-filter supports expressions containing
84-
both transforms and a final lookup.
85-
86-
.. _`lookup reference`: https://docs.djangoproject.com/en/stable/ref/models/lookups/#module-django.db.models.lookups
83+
Django's :mod:`lookup reference <django.db.models.lookups>`. django-filter supports
84+
expressions containing both transforms and a final lookup.
8785

8886

8987
Generating filters with Meta.fields
@@ -139,7 +137,7 @@ related model::
139137
Overriding default filters
140138
""""""""""""""""""""""""""
141139

142-
Like ``django.contrib.admin.ModelAdmin``, it is possible to override
140+
Like :class:`django.contrib.admin.ModelAdmin`, it is possible to override
143141
default filters for all the models fields of the same kind using
144142
``filter_overrides`` on the ``Meta`` class::
145143

@@ -170,10 +168,10 @@ default filters for all the models fields of the same kind using
170168
Request-based filtering
171169
~~~~~~~~~~~~~~~~~~~~~~~
172170

173-
The ``FilterSet`` may be initialized with an optional ``request`` argument. If
174-
a request object is passed, then you may access the request during filtering.
175-
This allows you to filter by properties on the request, such as the currently
176-
logged-in user or the ``Accepts-Languages`` header.
171+
The :class:`~django_filters.filterset.FilterSet` may be initialized with an
172+
optional ``request`` argument. If a request object is passed, then you may access
173+
the request during filtering. This allows you to filter by properties on the request,
174+
such as the currently logged-in user or the ``Accepts-Languages`` header.
177175

178176
.. note::
179177

@@ -209,10 +207,11 @@ those that are published and those that are owned by the logged-in user
209207
Filtering the related queryset for ``ModelChoiceFilter``
210208
""""""""""""""""""""""""""""""""""""""""""""""""""""""""
211209

212-
The ``queryset`` argument for ``ModelChoiceFilter`` and ``ModelMultipleChoiceFilter``
213-
supports callable behavior. If a callable is passed, it will be invoked with the
214-
``request`` as its only argument. This allows you to perform the same kinds of
215-
request-based filtering without resorting to overriding ``FilterSet.__init__``.
210+
The ``queryset`` argument for :class:`~django_filters.filters.ModelChoiceFilter` and
211+
:class:`~django_filters.filters.ModelMultipleChoiceFilter` supports callable behavior.
212+
If a callable is passed, it will be invoked with the ``request`` as its only argument.
213+
This allows you to perform the same kinds of request-based filtering without resorting
214+
to overriding ``FilterSet.__init__``.
216215

217216
.. code-block:: python
218217

@@ -277,7 +276,9 @@ We need a URL pattern to call the view::
277276
The template
278277
------------
279278

280-
And lastly we need a template::
279+
And lastly we need a template:
280+
281+
.. code-block:: django
281282

282283
{% extends "base.html" %}
283284

docs/ref/fields.txt

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,22 +2,23 @@
22
Field Reference
33
===============
44

5-
``IsoDateTimeField``
6-
~~~~~~~~~~~~~~~~~~~~
5+
.. module:: django_filters.fields
6+
:synopsis: Provided form fields and their arguments.
77

8-
Extends ``django.forms.DateTimeField`` to allow parsing ISO 8601 formated dates, in addition to existing formats
8+
.. currentmodule:: django_filters.fields
9+
10+
.. class:: IsoDateTimeField
11+
12+
Extends :class:`django.forms.DateTimeField` to allow parsing ISO 8601 formated dates, in addition to existing formats
913

1014
Defines a class level attribute ``ISO_8601`` as constant for the format.
1115

1216
Sets ``input_formats = [ISO_8601]`` — this means that by default ``IsoDateTimeField`` will **only** parse ISO 8601 formated dates.
1317

14-
You may set ``input_formats`` to your list of required formats as per the `DateTimeField Docs`_, using the ``ISO_8601`` class level attribute to specify the ISO 8601 format.
18+
You may set :attr:`~django.forms.DateTimeField.input_formats` to your list of required formats as per the :class:`~django.forms.DateTimeField` docs, using the ``ISO_8601`` class level attribute to specify the ISO 8601 format.
1519

1620
.. code-block:: python
1721

1822
f = IsoDateTimeField()
1923
f.input_formats = [IsoDateTimeField.ISO_8601] + DateTimeField.input_formats
2024

21-
22-
.. _`DateTimeField Docs`: https://docs.djangoproject.com/en/stable/ref/forms/fields/#django.forms.DateTimeField.input_formats
23-

0 commit comments

Comments
 (0)