From 0b70985f42da7a8eb2e206e6780681b7849564ef Mon Sep 17 00:00:00 2001 From: Nick Pope Date: Wed, 20 Mar 2019 18:30:43 +0000 Subject: Fixed #30240 -- Added SHA1, SHA224, SHA256, SHA384, and SHA512 database functions. Thanks Mariusz Felisiak and Tim Graham for reviews. --- docs/ref/models/database-functions.txt | 35 ++++++++++++++++++++++++++++++++++ docs/releases/3.0.txt | 7 ++++++- 2 files changed, 41 insertions(+), 1 deletion(-) (limited to 'docs') diff --git a/docs/ref/models/database-functions.txt b/docs/ref/models/database-functions.txt index 46b41251a0..b79f7972cf 100644 --- a/docs/ref/models/database-functions.txt +++ b/docs/ref/models/database-functions.txt @@ -1441,6 +1441,41 @@ side. Similar to :class:`~django.db.models.functions.Trim`, but removes only trailing spaces. +``SHA1``, ``SHA224``, ``SHA256``, ``SHA384``, and ``SHA512`` +------------------------------------------------------------ + +.. class:: SHA1(expression, **extra) +.. class:: SHA224(expression, **extra) +.. class:: SHA256(expression, **extra) +.. class:: SHA384(expression, **extra) +.. class:: SHA512(expression, **extra) + +.. versionadded:: 3.0 + +Accepts a single text field or expression and returns the particular hash of +the string. + +They can also be registered as transforms as described in :class:`Length`. + +Usage example:: + + >>> from django.db.models.functions import SHA1 + >>> Author.objects.create(name='Margaret Smith') + >>> author = Author.objects.annotate(name_sha1=SHA1('name')).get() + >>> print(author.name_sha1) + b87efd8a6c991c390be5a68e8a7945a7851c7e5c + +.. admonition:: PostgreSQL + + The `pgcrypto extension `_ must be installed. You can use the + :class:`~django.contrib.postgres.operations.CryptoExtension` migration + operation to install it. + +.. admonition:: Oracle + + Oracle doesn't support the ``SHA224`` function. + ``StrIndex`` ------------ diff --git a/docs/releases/3.0.txt b/docs/releases/3.0.txt index 3433d54183..71a8aef971 100644 --- a/docs/releases/3.0.txt +++ b/docs/releases/3.0.txt @@ -168,7 +168,12 @@ Migrations Models ~~~~~~ -* Added the :class:`~django.db.models.functions.MD5` database function. +* Added hash database functions :class:`~django.db.models.functions.MD5`, + :class:`~django.db.models.functions.SHA1`, + :class:`~django.db.models.functions.SHA224`, + :class:`~django.db.models.functions.SHA256`, + :class:`~django.db.models.functions.SHA384`, and + :class:`~django.db.models.functions.SHA512`. * The new ``is_dst`` parameter of the :class:`~django.db.models.functions.Trunc` database functions determines the -- cgit v1.3