Skip to content

Commit

Permalink
Infer verbose names from created objects' Metas
Browse files Browse the repository at this point in the history
  • Loading branch information
koterpillar committed Jan 13, 2016
1 parent 3c69456 commit 365a59b
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions aloe/steps/factoryboy.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,16 +99,17 @@ class Meta:
# Then I have created 10 users all with the first name Joe
"""

# Look for verbose_name and verbose_name_plural on the Meta of the classes
# factory creates; its own Meta cannot define arbitrary attributes.

try:
name = factory._meta.verbose_name # pylint:disable=protected-access
name = factory._meta.model._meta.verbose_name # pylint:disable=protected-access
except AttributeError:
name = camel_case_to_spaces(
re.sub('Factory$', '', factory.__name__))

try:
# pylint:disable=protected-access
plural = factory._meta.verbose_name_plural
# pylint:enable=protected-access
plural = factory._meta.model._meta.verbose_name_plural # pylint:disable=protected-access
except AttributeError:
plural = name + 's'

Expand Down

0 comments on commit 365a59b

Please sign in to comment.