Ticket #2701: serialize_limit_by_field.diff

File serialize_limit_by_field.diff, 1.3 KB (added by deryck@…, 18 years ago)

Provides fields as an optional paramter to serializers.serialize.

  • django/core/serializers/base.py

     
    2828        self.options = options
    2929
    3030        self.stream = options.get("stream", StringIO())
     31        self.selected_fields = options.get("fields")
    3132
    3233        self.start_serialization()
    3334        for obj in queryset:
     
    3637                if field is obj._meta.pk:
    3738                    continue
    3839                elif field.rel is None:
    39                     self.handle_field(obj, field)
     40                    if self.selected_fields is None or field.attname in self.selected_fields:
     41                        self.handle_field(obj, field)
    4042                else:
    41                     self.handle_fk_field(obj, field)
     43                    if self.selected_fields is None or field.attname[:-3] in self.selected_fields:
     44                        self.handle_fk_field(obj, field)
    4245            for field in obj._meta.many_to_many:
    43                 self.handle_m2m_field(obj, field)
     46                if self.selected_fields is None or field.attname in self.selected_fields:
     47                    self.handle_m2m_field(obj, field)
    4448            self.end_object(obj)
    4549        self.end_serialization()
    4650        return self.getvalue()
Back to Top