Add dynamic value to XML tags in Python



I am using XML renderer in Django-Rest-Framework. Which automaticaly renders the dictionary or list to XML. But in resulting XML tags i want some extra fields to be added. what should i do. What i thin is that i should change the key values of the dictionary. I don't know the way for it. TIA


Code Specification are as under:- Code in views



from django.shortcuts import render
from serializers import *
from rest_framework import viewsets
from rest_framework import status
from rest_framework.decorators import api_view
from rest_framework.response import Response
from feed.models import *
import collections

@api_view(['GET','POST'])
def feed(request):
try:
dub = propertyfinder.objects.all()
except dub.DoesNotExist:
return Response(status=status.HTTP_404_NOT_FOUND)
bcount = {}
if request.method == 'GET':
data = collections.OrderedDict()
prop = []
for i in dub:
data['reference_number'] = i.reference_number
data['offering_type'] = i.offering_type
data['property_type'] = i.property_type
data['price_on_application'] = i.price_on_application
prop.append(data)
bcount['dubizzlepropertyfeed'] = prop
return Response(bcount)


Output which i am getting



<list>
<property>
<reference_number>ref001</reference_number>
<offering_type>CR</offering_type>
<property_type>df</property_type>
<price_on_application>False</price_on_application>
</property>
</list>


Output which i want.



<list last_update="2014-08-08 13:14:15" listing_count="834">
<property last_update="2014-08-08 14:15:16">
<reference_number>
AB123
</reference_number>
<offering_type>
RR
</offering_type>
<property_type>
AP
</property_type>
<price>
1000000
</price>
<service_charge>
3000
</service_charge>
</property>
</list>

No comments:

Post a Comment