How to use 'django distinct' in Python

Every line of 'django distinct' code snippets is scanned for vulnerabilities by our powerful machine learning engine that combs millions of open source libraries, ensuring your Python code is secure.

All examples are scanned by Snyk Code

By copying the Snyk Code Snippets you agree to
this disclaimer
218def test_distinct(self):
219 self.assertEqual(self.manager.values_list(TestModel.a, flat=True), [1, 1, 2, 2])
220 self.assertEqual(self.manager.values_list(TestModel.a, flat=True).distinct(), [1, 2])
221 self.assertEqual(self.manager.values_list(TestModel.parent, flat=True).distinct(), self.PARENTS)
Important

Use secure code every time

Secure your code as it's written. Use Snyk Code to scan source code in minutes – no build needed – and fix issues immediately. Enable Snyk Code

502@async_test
503def test_distinct(self):
504 d = self.test_doc(a='a')
505 yield from d.save()
506
507 d = self.test_doc(a='a')
508 yield from d.save()
509
510 d = self.test_doc(a='b')
511 yield from d.save()
512
513 expected = ['a', 'b']
514 returned = yield from self.test_doc.objects.distinct('a')
515
516 self.assertEqual(returned, expected)

Related snippets