I need to return random data from models in json format but when I try random.choice I got the error 'Joke' object is not iterable .
views.py
def random_page(request):
random_joke = random.choice(Joke.objects.all())
jokes_list = serializers.serialize('json', random_joke)
return HttpResponse(jokes_list, content_type="text/json-comment-filtered")
models.py
from django.db import models
class Joke(models.Model):
joke = models.TextField(max_length=1000)
author = models.CharField(max_length=100, null=True)
def __str__(self):
return str(self.joke)