Open convers39 opened 3 years ago
Hi, you could perhaps use post-generation hooks.
In your example it would be something like
class ProductFactory(DjangoModelFactory):
# Rest of the stuff
@post_generation
def tags(self, create, extracted, **kwargs):
if not create:
return
if extracted:
self.tags.add(*extracted)
Then you just pass it a list of tags when you instantiate the object
...
product = ProductFactory(tags=['buff'])
...
I am writing tests and cannot figure out how to test with taggit field.
Here is my model:
And I am using factory_boy for testing, but seems tags cannot be used.
By default, factory boy will use the fields in the related model, however no matter I leave tags as blank, or assign it again with TaggableManager, I got an AttributeError.
Is that possible to use taggit with factory boy? Or are there any other methods to write a test with taggit? Very little information in the docs and StackOverflow about testing with taggit, really appreciate your help.