How can i create a xml file in django where the file is to contain objects from a queryset?
def my_serialize(request):
from django.core import serializers
data = serializers.serialize('xml', Student.objects.filter(Q(name__startswith='A')),
fields=('name','dob'))
from django.core.files import File
f = open('content.xml', 'w')
myfile = File(f)
myfile.write(data)
myfile.close()
After i call the above function, my content file remains empty, there is no data that gets written in it.
from django.core import serializers
data = serializers.serialize("xml", SomeModel.objects.all())
Take a look at the Serialization documentation.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With