Generic view for serialized queryset

4 views
Skip to first unread message

dchandek

unread,
Feb 23, 2007, 3:44:20 PM2/23/07
to Django developers, will....@duke.edu
FWIW, I didn't see anything like this in the distribution, and it
might be useful ...

def serialized(request, queryset, format, mimetype=None):
"""
Serialize queryset in specified format and return via HTTP
Standard mimetype for format can be overridden with provided value
"""
from django.http import HttpResponse
from django.core import serializers
content = serializers.serialize(format, queryset)
if mimetype is None:
if format == 'xml':
mimetype = 'application/xml'
elif format == 'json':
# http://www.ietf.org/rfc/rfc4627.txt
mimetype == 'application/json'
return HttpResponse(content=content, mimetype=mimetype)

Simon G.

unread,
Feb 24, 2007, 6:29:26 AM2/24/07
to Django developers
Hi dchandek,

This looks like an interesting idea - could you create a new ticket
for it at djangoproject.com, so it doesn't get lost?

Thanks,
Simon G.

On Feb 24, 9:44 am, "dchandek" <david.chandek.st...@duke.edu> wrote:
> FWIW, I didn't see anything like this in the distribution, and it
> might be useful ...
>
> def serialized(request, queryset, format, mimetype=None):
> """
> Serialize queryset in specified format and return via HTTP
> Standard mimetype for format can be overridden with provided value
> """
> from django.http import HttpResponse
> from django.core import serializers
> content = serializers.serialize(format, queryset)
> if mimetype is None:
> if format == 'xml':
> mimetype = 'application/xml'
> elif format == 'json':

> #http://www.ietf.org/rfc/rfc4627.txt

Reply all
Reply to author
Forward
0 new messages