88👍
DjangoJSONEncoder solved my problem.
import json
from django.core.serializers.json import DjangoJSONEncoder
data = json.dumps(data, cls=DjangoJSONEncoder)
5👍
Django’s serializers are only meant to be used on query sets; you will have to find a different way to solve your problem, such as converting the datetime
to something else first.
- [Django]-How to define default data for Django Models?
- [Django]-Django: How can I identify the calling view from a template?
- [Django]-Is get_or_create() thread safe
1👍
Whenever you see an error message of the form ... object has no attribute '_meta'
that is a clear-cut sign that a method was expecting a queryset but got something else. In this particular situation, serializers.serialize must have a queryset for its second argument. You can’t use a list, dictionary, etc., and definitely not a string.
Where is data
being set. Check to make sure it’s being assigned a true queryset. You might also want to post more of your code, if you’re still having issues. It’s difficult to diagnose the problem much more, out of context.
- [Django]-Adding links to full change forms for inline items in django admin?
- [Django]-Anyone knows good Django URL namespaces tutorial?
- [Django]-Multiple decorators for a view in Django: Execution order