The fillmydb module¶
-
class
fillmydb.
ModelWrapper
(*models)¶ Creates a wrapper around the models models that must be of the same type.
Parameters: models – The models to be wrapped and used afterwards for generating instances. Raises: ValueError – when the models are not of the same type (belong to different ORMs) -
generate
(*counts)¶ Generates and persists items. counts is a list of integers that indicate how many instances of each model should generate. The order is preserved from the models specified in constructor.
For example, if
wrapper
was declared asModelWrapper(Model1, Model2, Model3)
the following codewrapper.generate(10, 20, 15)
will generate 10 instances of
Model1
, 20 instances ofModel2
and 15 instances ofModel3
.Parameters: counts – the quantity of each item to be generated. Returns: None
-
-
class
fillmydb.
FieldSpec
(func, *args, **kwargs)¶ The generation logic for mock values for fields.
The mocked values of the fields will be generated as
func(*args, **kwargs)
.Parameters: - func – a callable object.
- args – the ordinal parameters
func
will be called with. - kwargs – the named parameters
func
will be called with.
-
resolve
()¶ Method that returns the generated value.
Returns: an object that will be directly assigned to the field when instantiating a model.
-
fillmydb.
initialize_django
(settings_py_path)¶ Initializes the environment required by Django. Must be called before importing your models:
import fillmydb fillmydb.initialize_django("path/to/settings.py") from mydjangoproject.myapp.models import MyModel, MyOtherModel ...
Parameters: settings_py_path – Path to the settings.py
file from your Django project.