python - post_generation with factory boy gives ManyRelatedManager when I wanted list -
I'm obviously going numpty, I will accept that at the very beginning I have the following factory
using the class DataSheetFactory (factory.DjangoModelFactory): class meta: model = model.model django_get_or_create = ('key_field',) key_field = factory. Equation (lambda n: N) ... & lt; Additional fields & gt; @ Factory. Post_generation def product_compressor (self, create, conclude, ** kwargs): if not created: removed if removed: For the person in the extracted: self.product_contributors.add (person)
< P> When I make it with PDS = DataSheetFactory (product_contributors = (& lt; Users' Tupal & gt;))
A list of users in the field product_contributors
Expecting, but a django.db.models.fields.related.ManyRelatedManager
instead, so the test does not work Ga. What should I do, as I have followed "common recipes"? Just to clarify, I am asking that a sample to use the factory boy to create a list of users in many areas. What I suggested in the docs, and I get a a lot of connected managers
, is not a list, so factory_boy
generates unusable examples. As mentioned above, your problem has come from magic which I have put in the factory:
Code> self is not an example of a factory in a @_genon
, but the actual object just generates.
In this way, product_contributors
is actually an example of Django's "related manager", you can access items with:
Datasheet = DataSetifier () Contributors = Datasheet.Product_ Contributor.L ()
Comments
Post a Comment