7
7
import warnings
8
8
import six
9
9
10
+ from django .apps import apps
11
+
10
12
from django_dynamic_fixture .ddf import DynamicFixture , Copier , DDFLibrary , \
11
13
set_pre_save_receiver , set_post_save_receiver
12
14
from django_dynamic_fixture .django_helper import print_field_values , django_greater_than
@@ -64,7 +66,7 @@ def _new(model, n=1, lesson=None, persist_dependencies=True, **kwargs):
64
66
Return one or many valid instances of Django Models with fields filled with auto generated or customized data.
65
67
All instances will NOT be persisted in the database, except its dependencies, in case @persist_dependencies is True.
66
68
67
- @model: The class of the Django model.
69
+ @model: The class of the Django model. It can be a string `<app_label>.<model_name>`
68
70
@n: number of instances to be created with the given configuration. Default is 1.
69
71
@lesson: use a custom lesson to build the model object.
70
72
@persist_dependencies: If True, save internal dependencies, otherwise just instantiate them. Default is True.
@@ -79,6 +81,8 @@ def _new(model, n=1, lesson=None, persist_dependencies=True, **kwargs):
79
81
80
82
Wrapper for the method DynamicFixture.new
81
83
"""
84
+ if isinstance (model , str ):
85
+ model = apps .get_model (model )
82
86
kwargs = look_up_alias (** kwargs )
83
87
d = fixture (** kwargs )
84
88
if n == 1 :
@@ -94,7 +98,7 @@ def _get(model, n=1, lesson=None, **kwargs):
94
98
Return one or many valid instances of Django Models with fields filled with auto generated or customized data.
95
99
All instances will be persisted in the database.
96
100
97
- @model: The class of the Django model.
101
+ @model: The class of the Django model. It can be a string `<app_label>.<model_name>`
98
102
@n: number of instances to be created with the given configuration. Default is 1.
99
103
@lesson: use a custom lesson to build the model object.
100
104
@@ -108,6 +112,8 @@ def _get(model, n=1, lesson=None, **kwargs):
108
112
109
113
Wrapper for the method DynamicFixture.get
110
114
"""
115
+ if isinstance (model , str ):
116
+ model = apps .get_model (model )
111
117
kwargs = look_up_alias (** kwargs )
112
118
d = fixture (** kwargs )
113
119
if n == 1 :
@@ -120,7 +126,7 @@ def _get(model, n=1, lesson=None, **kwargs):
120
126
121
127
def _teach (model , lesson = None , ** kwargs ):
122
128
'''
123
- @model: The class of the Django model.
129
+ @model: The class of the Django model. It can be a string `<app_label>.<model_name>`
124
130
@lesson: Name of custom lesson to be created.
125
131
126
132
@raise an CantOverrideLesson error if the same model/lesson were called twice.
@@ -136,6 +142,8 @@ def _teach(model, lesson=None, **kwargs):
136
142
`Shelve` becomes `Teach`
137
143
`Library` becomes `Lessons`
138
144
'''
145
+ if isinstance (model , str ):
146
+ model = apps .get_model (model )
139
147
kwargs = look_up_alias (** kwargs )
140
148
d = fixture (** kwargs )
141
149
return d .teach (model , lesson = lesson , ** kwargs )
0 commit comments