Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

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
  • Loading branch information...
commit e39a8e947e5209533657405568992213e87bd532 1 parent d4d1a22
@jacobian jacobian authored
Showing with 7 additions and 3 deletions.
  1. +7 −3 django/core/serializers/base.py
View
10 django/core/serializers/base.py
@@ -28,6 +28,7 @@ def serialize(self, queryset, **options):
self.options = options
self.stream = options.get("stream", StringIO())
+ self.selected_fields = options.get("fields")
self.start_serialization()
for obj in queryset:
@@ -36,11 +37,14 @@ def serialize(self, queryset, **options):
if field is obj._meta.pk:
continue
elif field.rel is None:
- self.handle_field(obj, field)
+ if self.selected_fields is None or field.attname in self.selected_fields:
+ self.handle_field(obj, field)
else:
- self.handle_fk_field(obj, field)
+ 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:
- self.handle_m2m_field(obj, field)
+ 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()
return self.getvalue()
Please sign in to comment.
Something went wrong with that request. Please try again.