def generate_random_single_choice(self): user = self.get_random_user() title = self.get_random_title() poll = Poll(user=user, title=title) poll.timestamp = get_timestamp_in_milli() poll.date_begin = get_timestamp_in_milli() + 60000 * 60 * 24 * (random.randint(0, 4) - 2) poll.date_end = poll.date_begin + 60000 * 60 * 24 * random.randint(5, 30) poll.paid = False poll.is_active = True poll.poll_type = 1 poll.total_answered_count = 0 poll.status = APPROVED photo_name = self.get_random_photo_name() poll.image.save(str(get_timestamp_in_milli()) + photo_name, File(open(PHOTO_PATH + photo_name, 'r'))) poll.save() choice_count = random.randint(3, 10) for i in xrange(choice_count): new_choice = PollChoice() new_choice.poll = poll new_choice.sc_value = self.get_random_choice() new_choice.priority = i + 1 new_choice.timestamp = get_timestamp_in_milli() new_choice.save() self.add_random_category(poll) self.add_random_keyword(poll) poll.save() return poll