diff --git a/golem_season/models/golem_season.py b/golem_season/models/golem_season.py index f2d7aed..9b1dc6e 100644 --- a/golem_season/models/golem_season.py +++ b/golem_season/models/golem_season.py @@ -54,11 +54,10 @@ class GolemSeason(models.Model): """ Check if end date if after start date and if there is no conflict with existing periods """ for season in self: - if season.date_start: - if not season.date_end: + if season.date_start or season.date_end: + if season.date_start and not season.date_end: raise models.ValidationError(_('The date end is required')) - if season.date_end: - if not season.date_start: + elif season.date_end and not season.date_start: raise models.ValidationError(_('The date start is required')) if season.date_start > season.date_end: diff --git a/golem_season/tests/test_golem_season.py b/golem_season/tests/test_golem_season.py index 6d60925..0080c71 100644 --- a/golem_season/tests/test_golem_season.py +++ b/golem_season/tests/test_golem_season.py @@ -55,13 +55,18 @@ class TestGolemSeason(TransactionCase): 'date_start': '2009-11-01', 'date_end': '2011-12-31'}) + + self.assertTrue({'name': 'date_end and date_start is empty', + 'date_start': False, + 'date_end': False}) + with self.assertRaises(ValidationError): - self.season_model.create({'name': 'date_end is nul', + self.season_model.create({'name': 'date_end is empty', 'date_start': '2009-11-01', 'date_end': False}) with self.assertRaises(ValidationError): - self.season_model.create({'name': 'date_start is nul', + self.season_model.create({'name': 'date_start is empty', 'date_start' : False, 'date_end': '2009-11-01'})