Fixed #2701: Added "fields" argument to serializers.serialize. Thanks, Deryck.
git-svn-id: http://code.djangoproject.com/svn/django/trunk@4042 bcc190cf-cafb-0310-a4f2-bffc1f526a37
This commit is contained in:
parent
d4d1a22730
commit
e39a8e947e
|
@ -28,6 +28,7 @@ class Serializer(object):
|
|||
self.options = options
|
||||
|
||||
self.stream = options.get("stream", StringIO())
|
||||
self.selected_fields = options.get("fields")
|
||||
|
||||
self.start_serialization()
|
||||
for obj in queryset:
|
||||
|
@ -36,10 +37,13 @@ class Serializer(object):
|
|||
if field is obj._meta.pk:
|
||||
continue
|
||||
elif field.rel is None:
|
||||
if self.selected_fields is None or field.attname in self.selected_fields:
|
||||
self.handle_field(obj, field)
|
||||
else:
|
||||
if self.selected_fields is None or field.attname[:-3] in self.selected_fields:
|
||||
self.handle_fk_field(obj, field)
|
||||
for field in obj._meta.many_to_many:
|
||||
if self.selected_fields is None or field.attname in self.selected_fields:
|
||||
self.handle_m2m_field(obj, field)
|
||||
self.end_object(obj)
|
||||
self.end_serialization()
|
||||
|
|
Loading…
Reference in New Issue