Refs #31541 -- Added example of creating Redirect objects to redirects app docs.
This commit is contained in:
parent
0ff3228844
commit
a8c0246ece
|
@ -74,6 +74,24 @@ Via the Python API
|
||||||
Redirects are represented by a standard :doc:`Django model </topics/db/models>`,
|
Redirects are represented by a standard :doc:`Django model </topics/db/models>`,
|
||||||
which lives in :source:`django/contrib/redirects/models.py`. You can access
|
which lives in :source:`django/contrib/redirects/models.py`. You can access
|
||||||
redirect objects via the :doc:`Django database API </topics/db/queries>`.
|
redirect objects via the :doc:`Django database API </topics/db/queries>`.
|
||||||
|
For example::
|
||||||
|
|
||||||
|
>>> from django.conf import settings
|
||||||
|
>>> from django.contrib.redirects.models import Redirect
|
||||||
|
>>> # Add a new redirect.
|
||||||
|
>>> redirect = Redirect.objects.create(
|
||||||
|
... site_id=1,
|
||||||
|
... old_path='/contact-us/',
|
||||||
|
... new_path='/contact/',
|
||||||
|
... )
|
||||||
|
>>> # Change a redirect.
|
||||||
|
>>> redirect.new_path = '/contact-details/'
|
||||||
|
>>> redirect.save()
|
||||||
|
>>> redirect
|
||||||
|
<Redirect: /contact-us/ ---> /contact-details/>
|
||||||
|
>>> # Delete a redirect.
|
||||||
|
>>> Redirect.objects.filter(site_id=1, old_path='/contact-us/').delete()
|
||||||
|
(1, {'redirects.Redirect': 1})
|
||||||
|
|
||||||
Middleware
|
Middleware
|
||||||
==========
|
==========
|
||||||
|
|
Loading…
Reference in New Issue