def random_date(self, start=None, end=None): if not end: end = timezone.now() if not start: start = end - timedelta(days=365) if start == end: return end return ms_to_datetime(self.random.randrange(datetime_to_ms(start), datetime_to_ms(end)))