1
0
mirror of https://github.com/django/django.git synced 2025-10-23 21:59:11 +00:00

Fixed #32060 -- Added Random database function.

This commit is contained in:
Nick Pope
2020-07-16 23:32:46 +01:00
committed by Mariusz Felisiak
parent f87b0ecd37
commit 06c5d3fafc
12 changed files with 51 additions and 27 deletions

View File

@@ -0,0 +1,13 @@
from django.db.models.functions import Random
from django.test import TestCase
from ..models import FloatModel
class RandomTests(TestCase):
def test(self):
FloatModel.objects.create()
obj = FloatModel.objects.annotate(random=Random()).first()
self.assertIsInstance(obj.random, float)
self.assertGreaterEqual(obj.random, 0)
self.assertLess(obj.random, 1)