From f591f66634e82b9443f788df4e8bb97d86bd0e58 Mon Sep 17 00:00:00 2001 From: j Date: Sat, 4 Aug 2018 16:51:43 +0100 Subject: [PATCH] try date formats --- pandora/item/models.py | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/pandora/item/models.py b/pandora/item/models.py index fe7ad08a..7ee4efa8 100644 --- a/pandora/item/models.py +++ b/pandora/item/models.py @@ -1032,9 +1032,16 @@ class Item(models.Model): elif sort_type == 'date': value = self.get(source) if isinstance(value, string_types): - value = datetime_safe.datetime.strptime(value, '%Y-%m-%d') - set_value(s, name, value) - + value_ = None + for fmt in ('%Y-%m-%d', '%Y-%m', '%Y'): + try: + value_ = datetime_safe.datetime.strptime(value, fmt) + except ValueError: + pass + else: + continue + if value_ is not None: + set_value(s, name, value_) s.save() def update_facet(self, key):