Skip to content

Commit

Permalink
Use a less tricky implementation of fallback_to_any
Browse files Browse the repository at this point in the history
  • Loading branch information
matthiask committed Jul 27, 2020
1 parent 22686e3 commit aa1e324
Showing 1 changed file with 7 additions and 11 deletions.
18 changes: 7 additions & 11 deletions translated_fields/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,17 +23,13 @@ def getter(self):
def fallback_to_any(name, field):
def getter(self):
current = getattr(self, to_attribute(name), None)

return current or next(
filter(
None,
(
getattr(self, to_attribute(name, language))
for language in field.languages
),
),
"",
)
if current:
return current
for language in field.languages:
value = getattr(self, to_attribute(name, language))
if value:
return value
return ""

return getter

Expand Down

0 comments on commit aa1e324

Please sign in to comment.