Ticket #5711: patch2.diff

File patch2.diff, 2.0 KB (added by anonymous, 17 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('extra', 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 
     33        self.select_extra = options.get("extra", False)
     34       
    3435        self.start_serialization()
    3536        for obj in queryset:
    3637            self.start_object(obj)
     
    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            if queryset._select is not None and self.select_extra:
     51                for field in queryset._select.keys():
     52                    self.handle_extra(obj, field)
    4953            self.end_object(obj)
    5054        self.end_serialization()
    5155        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_extra(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