Ticket #5711: patch.diff

File patch.diff, 1.9 KB (added by wnielson, 8 years ago)
  • core/serializers/json.py

     
    2323    def end_serialization(self):
    2424        self.options.pop('stream', None)
    2525        self.options.pop('fields', None)
     26        self.options.pop('attrs', None)
    2627        simplejson.dump(self.objects, self.stream, cls=DjangoJSONEncoder, **self.options)
    2728
    2829    def getvalue(self):
  • core/serializers/base.py

     
    3030
    3131        self.stream = options.get("stream", StringIO())
    3232        self.selected_fields = options.get("fields")
     33        self.selected_attrs = options.get("attrs", [])
    3334
    3435        self.start_serialization()
    3536        for obj in queryset:
     
    4647                if field.serialize:
    4748                    if self.selected_fields is None or field.attname in self.selected_fields:
    4849                        self.handle_m2m_field(obj, field)
     50            for attr in self.selected_attrs:
     51                self.handle_attr(obj, attr)
    4952            self.end_object(obj)
    5053        self.end_serialization()
    5154        return self.getvalue()
  • core/serializers/python.py

     
    3434
    3535    def handle_field(self, obj, field):
    3636        self._current[field.name] = smart_unicode(getattr(obj, field.name), strings_only=True)
     37   
     38    def handle_attr(self, obj, field):
     39        self._current[field] = smart_unicode(getattr(obj, field), strings_only=True)
    3740
    3841    def handle_fk_field(self, obj, field):
    3942        related = getattr(obj, field.name)
Back to Top