Here, I will explain what is fixture in django and how it is used.
Fixture is Collection of data that is in a specific format. It is use to load initial data into Django models. Fixture can be written in JSON, XML and YAML format.
2. Agenda
What is Django Fixture?
Syntax
Example
Insert Data to Django models
Supported Format and Data structures
3. What is
Django
Fixture?
Collection of data that is in a
specific format.
Use to load initial data into
Django models.
Fixture can be written in JSON,
XML and YAML format.
4. Syntax - Load fixturedata into Database tables
python manage.py loaddata fixture_file.json
This will read fixture data from the fixture file and insert the data
into Database table.
13. Using YAML file
The same information can be put into a YAML and that would look like
following:
- model: myapp.person
pk: 1
fields:
name: Amit
company: Acenture
city: Pune
14. Using XML file
The same information can be put into a XML and that would look like following:
<?xml version="1.0" encoding="UTF-8"?>
<django-objectsversion="1.0">
<object pk="1" model="myapp.Student">
<field type="CharField" name="name">Amit</field>
<field type="CharField" name="company">Accenture</field>
<field type="CharField" name="city">Pune</field>
</object>
</django-objects>