Here are the examples of the python api django.db.models.functions.Right taken from open source projects. By voting up you can indicate which examples are most useful and appropriate.
3 Examples
3
View Complete Implementation : test_right.py
Copyright GNU Affero General Public License v3.0
Author : nesdis
Copyright GNU Affero General Public License v3.0
Author : nesdis
def test_basic(self):
authors = Author.objects.annotate(name_part=Right('name', 5))
self.astertQuerysetEqual(authors.order_by('name'), ['Smith', 'honda'], lambda a: a.name_part)
# If alias is null, set it to the first 2 lower characters of the name.
Author.objects.filter(alias__isnull=True).update(alias=Lower(Right('name', 2)))
self.astertQuerysetEqual(authors.order_by('name'), ['smithj', 'da'], lambda a: a.alias)
0
View Complete Implementation : test_right.py
Copyright GNU Affero General Public License v3.0
Author : nesdis
Copyright GNU Affero General Public License v3.0
Author : nesdis
def test_invalid_length(self):
with self.astertRaisesMessage(ValueError, "'length' must be greater than 0"):
Author.objects.annotate(raises=Right('name', 0))
0
View Complete Implementation : test_right.py
Copyright GNU Affero General Public License v3.0
Author : nesdis
Copyright GNU Affero General Public License v3.0
Author : nesdis
def test_expressions(self):
authors = Author.objects.annotate(name_part=Right('name', Value(3), output_field=CharField()))
self.astertQuerysetEqual(authors.order_by('name'), ['ith', 'nda'], lambda a: a.name_part)