77import warnings
88import six
99
10+ from django .apps import apps
11+
1012from django_dynamic_fixture .ddf import DynamicFixture , Copier , DDFLibrary , \
1113 set_pre_save_receiver , set_post_save_receiver
1214from 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):
6466 Return one or many valid instances of Django Models with fields filled with auto generated or customized data.
6567 All instances will NOT be persisted in the database, except its dependencies, in case @persist_dependencies is True.
6668
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>`
6870 @n: number of instances to be created with the given configuration. Default is 1.
6971 @lesson: use a custom lesson to build the model object.
7072 @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):
7981
8082 Wrapper for the method DynamicFixture.new
8183 """
84+ if isinstance (model , str ):
85+ model = apps .get_model (model )
8286 kwargs = look_up_alias (** kwargs )
8387 d = fixture (** kwargs )
8488 if n == 1 :
@@ -94,7 +98,7 @@ def _get(model, n=1, lesson=None, **kwargs):
9498 Return one or many valid instances of Django Models with fields filled with auto generated or customized data.
9599 All instances will be persisted in the database.
96100
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>`
98102 @n: number of instances to be created with the given configuration. Default is 1.
99103 @lesson: use a custom lesson to build the model object.
100104
@@ -108,6 +112,8 @@ def _get(model, n=1, lesson=None, **kwargs):
108112
109113 Wrapper for the method DynamicFixture.get
110114 """
115+ if isinstance (model , str ):
116+ model = apps .get_model (model )
111117 kwargs = look_up_alias (** kwargs )
112118 d = fixture (** kwargs )
113119 if n == 1 :
@@ -120,7 +126,7 @@ def _get(model, n=1, lesson=None, **kwargs):
120126
121127def _teach (model , lesson = None , ** kwargs ):
122128 '''
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>`
124130 @lesson: Name of custom lesson to be created.
125131
126132 @raise an CantOverrideLesson error if the same model/lesson were called twice.
@@ -136,6 +142,8 @@ def _teach(model, lesson=None, **kwargs):
136142 `Shelve` becomes `Teach`
137143 `Library` becomes `Lessons`
138144 '''
145+ if isinstance (model , str ):
146+ model = apps .get_model (model )
139147 kwargs = look_up_alias (** kwargs )
140148 d = fixture (** kwargs )
141149 return d .teach (model , lesson = lesson , ** kwargs )
0 commit comments