-
Notifications
You must be signed in to change notification settings - Fork 0
data
Adrian Wilke edited this page Sep 12, 2024
·
1 revision
- https://docs.djangoproject.com/en/4.2/howto/initial-data/
- https://docs.djangoproject.com/en/4.2/topics/serialization/
python manage.py shell
from django.core import serializers
from events.models import Country
data = serializers.serialize("xml", Country.objects.all())
f = open("events/fixtures/country.xml", "w")
f.write(data)
f.close()
exit()
print(data)
# <?xml version="1.0" encoding="utf-8"?>
# <django-objects version="1.0"><object model="events.country" pk="1"><field name="title" type="CharField">Germany</field></object></django-objects>
python manage.py shell
from django.core import serializers
f = open("events/fixtures/country.xml", "r")
data = f.read()
f.close()
for obj in serializers.deserialize("xml", data):
obj.save()
exit()