You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Most m2m relation handling for factories in Django is pretty simple, is this of interest?
classManyToManyPostGeneration(factory.PostGeneration):
""" Simplified factory post_generation for many-to-many relationships - sets values passed to the collection https://factoryboy.readthedocs.io/en/latest/recipes.html?highlight=many#simple-many-to-many-relationship Arguments: name: the name of the many-to-many relation Usage: You can pass the factory a list of model instances - article_factory.create(tags=LazyFixture(lambda tag: [tag]))) Or you can use the parametrize decorator - @pytest.mark.parametrize('article__tags', [LazyFixture(lambda tag: [tag])]) """def__init__(self, name):
deffunc(self, create, extracted, **kwargs):
ifcreateandextracted:
getattr(self, name).set(extracted)
func.__name__=namereturnsuper().__init__(func)
I'd drop the string arg but I couldn't figure out how to know the relation name otherwise
Another thought was whether it should add or set – the examples provided use add but I figure given the whole list is passed in an explicit set is probably what is expected (i.e. clobber)
Any interest in something like this in pytest-factoryboy?
The text was updated successfully, but these errors were encountered:
Most m2m relation handling for factories in Django is pretty simple, is this of interest?
Makes basic m2m declarations as simple as
You can also define and use the inverse side too
I'd drop the string arg but I couldn't figure out how to know the relation name otherwise
Another thought was whether it should
add
orset
– the examples provided useadd
but I figure given the whole list is passed in an explicitset
is probably what is expected (i.e. clobber)Any interest in something like this in pytest-factoryboy?
The text was updated successfully, but these errors were encountered: