Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Document callable and iterable attribute values #27

Closed
richardebeling opened this issue Apr 17, 2019 · 2 comments
Closed

Document callable and iterable attribute values #27

richardebeling opened this issue Apr 17, 2019 · 2 comments
Labels
documentation Improvements or additions to documentation good first issue Good for newcomers

Comments

@richardebeling
Copy link

It is documented that recipes can have callables and iterators as value here

The source code looks like you can do the same thing when not using custom recipes but rather just mommy.make(Class, **attrs):
https://github.com/berinhard/model_mommy/blob/2f8948ce1d8ee5c29d097d1890bcf2811ef0e80c/model_mommy/mommy.py#L282 and
https://github.com/berinhard/model_mommy/blob/2f8948ce1d8ee5c29d097d1890bcf2811ef0e80c/model_mommy/mommy.py#L284

Also, using it works perfectly fine:

>>> def random_name():
...     return random.choice(["Paul Molive", "Anna Mull", "Gail Forcewind"])
...
>>> users = mommy.make(UserProfile, _quantity=5, last_name=random_name)
>>> [u.last_name for u in users]
['Gail Forcewind', 'Anna Mull', 'Gail Forcewind', 'Anna Mull', 'Paul Molive']
>>> 
>>> name_iterable = ("Anna Sthesia", "Paige Turner", "Bob Frapples")
>>> users = mommy.make(UserProfile, _quantity=5, last_name=itertools.cycle(name_iterable))
>>> [u.last_name for u in users]
['Anna Sthesia', 'Paige Turner', 'Bob Frapples', 'Anna Sthesia', 'Paige Turner']

Is this a feature? If so, I think it should be documented here

Related issue: berinhard/model_mommy#81

Versions

Python: 3.7.1
Django: 2.2
Model Mommy: 1.6.0

@richardebeling richardebeling changed the title Document callable and iteratable attribute values Document callable and iterable attribute values Apr 17, 2019
@berinhard berinhard transferred this issue from berinhard/model_mommy Oct 22, 2019
@berinhard berinhard added documentation Improvements or additions to documentation good first issue Good for newcomers labels Jan 20, 2020
@magdumsuraj07
Copy link
Contributor

Hi, I am working on this issue. I have raised one PR here: #309

Please check it out and let me know if any changes are required.

@berinhard
Copy link
Member

Fixed by #309

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
documentation Improvements or additions to documentation good first issue Good for newcomers
Projects
None yet
Development

No branches or pull requests

3 participants