2๐
Iโve used Django Dynamic Fixtures for several years and found it really great. It generates fixtures based on your model definitions.
If you have a model Project
you can generate your fixtures in a test environment using the command G(Project)
and optionally customize it with G(Project, name='test')
etc.
from django_dynamic_fixture import G
from apps.projects.models import Project
class TestProject(TestCase):
"""
Test project name
"""
def setUp(self):
self.project1 = G(Project)
self.project2 = G(Project, name="my project")
def test_project(self):
self.assertTrue(self.project1)
def test_name(self):
self.assertEqual(self.project2.name, "my project")
๐คdjq
0๐
How about using serializers of DRF? (or any library that you are familiar with)
You can serialize objects to json easily using DRF.
Just output them to file.
๐คeugene
- [Answered ]-Json formatting trouble, when updating or editing my json file
- [Answered ]-Incremented CharField
- [Answered ]-Django CMS simple placeholders outside of cms
Source:stackexchange.com