Commit 27de6840 authored by okhin's avatar okhin 🚴

Let's use a get or create for the tag factory

parent de047352
......@@ -12,6 +12,7 @@ from .models import Article, STATUS_CHOICES
class TagFactory(factory.django.DjangoModelFactory):
class Meta:
model = Tag
django_get_or_create = ('name',)
name = factory.Faker("word")
......@@ -39,11 +40,4 @@ class ArticleFactory(factory.django.DjangoModelFactory):
quote = choice([True, False])
speak = choice([True, False])
@factory.post_generation
def tags(self, create, extracted, **kwargs):
if not create:
return
if extracted:
for tag in extracted:
self.tags.add(tag)
tags = factory.RelatedFactoryList(TagFactory, size=lambda: randint(1, 10))
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment