I have look at this question: In Django, how do I select 100 random records from the database?
And attempted to make use of Content.objects.all().order_by('?')[:30], but this can produce some duplicate products. Just how could I choose 30 unique random values from database?

For those who have a workable quantity of records within the database (ie not 1000's), this works, and despite the fact that it hits the db two times it'll most likely considerably more effective than order_by('?').

import random
content_pks = Content.objects.values_list('pk', flat=True)
selected_pks = random.sample(content_pks, 30)
content_objects = Content.objects.filter(pk__in=selected_pks)