try date formats

This commit is contained in:
j 2018-08-04 16:51:43 +01:00
parent 1d6d53e282
commit f591f66634

View file

@ -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):