Ticket #2843: svn.2.diff
File svn.2.diff, 3.7 KB (added by , 18 years ago) |
---|
-
django/core/serializers/xml_serializer.py
5 5 from django.conf import settings 6 6 from django.core.serializers import base 7 7 from django.db import models 8 from django.db.models.fields.related import OneToOneRel 8 9 from django.utils.xmlutils import SimplerXMLGenerator 9 10 from xml.dom import pulldom 10 11 … … 88 89 self.xml.addQuickElement("object", attrs={"pk" : str(relobj._get_pk_val())}) 89 90 self.xml.endElement("field") 90 91 92 def handle_o2m_field(self, obj, field): 93 if not isinstance(field.field.rel, OneToOneRel): 94 self.xml.startElement("field", { 95 "name" : field.get_accessor_name(), 96 "rel" : field.field.rel.__class__.__name__, 97 "to" : field.field.name, 98 }) 99 for relobj in getattr(obj, field.get_accessor_name()).iterator(): 100 self.xml.addQuickElement("object", attrs={"pk" : str(relobj._get_pk_val())}) 101 self.xml.endElement("field") 102 91 103 def _start_relational_field(self, field): 92 104 """ 93 105 Helper to output the <field> element for relational fields … … 214 226 inner_text.extend(getInnerText(child)) 215 227 else: 216 228 pass 217 return "".join(inner_text) 218 No newline at end of file 229 return "".join(inner_text) -
django/core/serializers/base.py
29 29 30 30 self.stream = options.get("stream", StringIO()) 31 31 32 self.export_o2m = options.get("export_o2m", False) 33 if self.options.has_key("export_o2m"): 34 del self.options["export_o2m"] 35 32 36 self.start_serialization() 33 37 for obj in queryset: 34 38 self.start_object(obj) … … 41 45 self.handle_fk_field(obj, field) 42 46 for field in obj._meta.many_to_many: 43 47 self.handle_m2m_field(obj, field) 48 if self.export_o2m: 49 for field in obj._meta.get_all_related_objects(): 50 self.handle_o2m_field(obj, field) 44 51 self.end_object(obj) 45 52 self.end_serialization() 46 53 return self.getvalue() … … 103 110 """ 104 111 raise NotImplementedError 105 112 113 def handle_o2m_field(self, obj, field): 114 """ 115 Called to handle a OneToManyField. 116 """ 117 raise NotImplementedError 118 106 119 def getvalue(self): 107 120 """ 108 121 Return the fully serialized queryset. -
django/core/serializers/python.py
7 7 from django.conf import settings 8 8 from django.core.serializers import base 9 9 from django.db import models 10 from django.db.models.fields.related import OneToOneRel 10 11 11 12 class Serializer(base.Serializer): 12 13 """ … … 43 44 def handle_m2m_field(self, obj, field): 44 45 self._current[field.name] = [related._get_pk_val() for related in getattr(obj, field.name).iterator()] 45 46 47 def handle_o2m_field(self, obj, field): 48 if not isinstance(field.field.rel, OneToOneRel): 49 self._current[field.get_accessor_name()] = [related._get_pk_val() for related in getattr(obj, field.get_accessor_name()).iterator()] 50 46 51 def getvalue(self): 47 52 return self.objects 48 53