Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
La Quadrature du Net
rpteam
Revue de Press
Commits
27de6840
Commit
27de6840
authored
Jul 04, 2019
by
Okhin
Browse files
Let's use a get or create for the tag factory
parent
de047352
Changes
1
Hide whitespace changes
Inline
Side-by-side
apps/rp/factories.py
View file @
27de6840
...
...
@@ -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
))
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment