Skip to content

Commit

Permalink
Enable seq to be imported from baker
Browse files Browse the repository at this point in the history
Enable the seq() function to be imported from the baker module like
it is in the recipe module so that it can be used as baker.seq() if
preferred or to avoid namespace issues.

The current import can be left in place for backwards compatibility
or to continue importing seq as before.

Closes model-bakers#75
  • Loading branch information
radwon committed Jun 4, 2020
1 parent 0256cf6 commit e78f681
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 5 deletions.
8 changes: 3 additions & 5 deletions docs/source/recipes.rst
Original file line number Diff line number Diff line change
Expand Up @@ -225,20 +225,18 @@ Sometimes, you have a field with an unique value and using ``make`` can cause ra
This will append a counter to strings to avoid uniqueness problems and it will sum the counter with numerical values.

Sequences and iterables can be used not only for recipes, but with ``baker.make`` as well:
Sequences and iterables can be used not only for recipes, but with ``baker`` as well:

.. code-block:: python
# it can be imported directly from model_bakery
>>> from model_bakery import seq
>>> from model_bakery import baker
>>> customer = baker.make('Customer', name=seq('Joe'))
>>> customer = baker.make('Customer', name=baker.seq('Joe'))
>>> customer.name
'Joe1'
>>> customers = baker.make('Customer', name=seq('Chad'), _quantity=3)
>>> customers = baker.make('Customer', name=baker.seq('Chad'), _quantity=3)
>>> for customer in customers:
... print(customer.name)
'Chad1'
Expand Down
2 changes: 2 additions & 0 deletions model_bakery/baker.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@
InvalidCustomBaker,
)
from .utils import import_from_str
# Enable seq to be imported from baker
from .utils import seq # NoQA

recipes = None

Expand Down

0 comments on commit e78f681

Please sign in to comment.