Answer the question
In order to leave comments, you need to log in
Python + json, why is the array not being serialized?
Tell me please. Why doesn't it serialize a list of Tiket objects for me???
I want to send an array to the page on an ajax request and change the data there. Gets the list normally. The problem is wrapping in json
Here is the code:
def opens(request):
t = Tiket.objects.filter(user=request.user, sost=True)
return JsonResponse({'tiketsS':t})
Answer the question
In order to leave comments, you need to log in
t = Tiket.objects.filter(user=request.user, sost=True)
t = Tiket.objects.filter(user=request.user, sost=True).values()
return JsonResponse({'tiketsS': list(t)})
Most likely your objects have non-serializable types. Try to convert via json.dumps(t) and catch the exception.
Most likely your objects have non-serializable types. Try to convert via json.dumps(t) and catch the exception.
class Tiket(models.Model):
user = models.ForeignKey(User)
name = models.CharField(max_length=350)
info = models.TextField()
sost = models.BooleanField(default=True) # True - открыт тикет
date = models.DateTimeField('Дата создания')
manager = models.ForeignKey(Manager_cab) # Прикреплен ли менеджер
new_mess = models.BooleanField(default=False)
kol_mess = models.IntegerField(default=0)
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question