diff options
| author | Yash Saini <yash.saini275@gmail.com> | 2020-06-23 12:19:51 +0200 |
|---|---|---|
| committer | Mariusz Felisiak <felisiak.mariusz@gmail.com> | 2020-06-23 20:21:43 +0200 |
| commit | 648f6ffcd700de4990957c84000484f066b9edb2 (patch) | |
| tree | 9924cc42957b5d80d102b9ba1e02431d760a12ef | |
| parent | 59dcbdaed4e1827e0542f48a0a53453a1da50ca8 (diff) | |
[3.1.x] Refs #31541 -- Added example of creating Redirect objects to redirects app docs.
Backport of a8c0246ece0716cea2ea6c1b313d4d93a10ee333 from master
| -rw-r--r-- | docs/ref/contrib/redirects.txt | 18 |
1 files changed, 18 insertions, 0 deletions
diff --git a/docs/ref/contrib/redirects.txt b/docs/ref/contrib/redirects.txt index 6fa5fc51eb..45b7fe1a0e 100644 --- a/docs/ref/contrib/redirects.txt +++ b/docs/ref/contrib/redirects.txt @@ -74,6 +74,24 @@ Via the Python API Redirects are represented by a standard :doc:`Django model </topics/db/models>`, which lives in :source:`django/contrib/redirects/models.py`. You can access 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 ========== |
