def days(self, create, extracted, **kwargs): if not create: # Simple build, do nothing. return participants_limit = random.choice(range(180, 221, 10)) for date in daterange(self.start_date, self.end_date): ConferenceDaysFactory.create( day=date, participants_limit=participants_limit, conference=self, )
def _generate(self): start = self.start_date + relativedelta(months=self.current_month) end = start + relativedelta(months=self.current_month + 1) - relativedelta(days=3) date = None is_unique = False while not is_unique: date = FuzzyDate(datetime(start.year, start.month, 1), datetime(end.year, end.month, end.day)).fuzz() is_unique = date not in self.generated_dates[self.current_month] self.generated_dates[self.current_month].update( i for i in daterange(date - timedelta(days=3), date + timedelta(days=3)) ) return date