def setUp(self): self.data = [ Poll(id=1, question="Question 1", pub_date=timezone.now()), Poll(id=2, question="Question 2", pub_date=timezone.now()), Poll(id=3, question="Question 3", pub_date=timezone.now()), Poll(id=4, question="Question 4", pub_date=timezone.now()), Poll(id=5, question="Question 5", pub_date=timezone.now()), ] self.data_with_excluded_fields = [ PollWithExcludeFields(id=1, question="Question 1", pub_date=timezone.now()), PollWithExcludeFields(id=2, question="Question 2", pub_date=timezone.now()), PollWithExcludeFields(id=3, question="Question 3", pub_date=timezone.now()), PollWithExcludeFields(id=4, question="Question 4", pub_date=timezone.now()), PollWithExcludeFields(id=5, question="Question 5", pub_date=timezone.now()), ]
def setUp(self): self.data = [ Poll(id=1, question="Question 1", pub_date=now()), Poll(id=2, question="Question 2", pub_date=now()), Poll(id=3, question="Question 3", pub_date=now()), Poll(id=4, question="Question 4", pub_date=now()), Poll(id=5, question="Question 5", pub_date=now()), ]
def setUp(self): self.data = [ Poll(id=1, question="Question 1", pub_date=timezone.now()), Poll(id=2, question="Question 2", pub_date=timezone.now()), Poll(id=3, question="Question 3", pub_date=timezone.now()), Poll(id=4, question="Question 4", pub_date=timezone.now()), Poll(id=5, question="Question 5", pub_date=timezone.now()), ] bulk_create_with_history(self.data, Poll) self.data[3].question = "Updated question"
def setUp(self): self.data = [ Poll(id=1, question="Question 1", pub_date=timezone.now()), Poll(id=2, question="Question 2", pub_date=timezone.now()), Poll(id=3, question="Question 3", pub_date=timezone.now()), Poll(id=4, question="Question 4", pub_date=timezone.now()), Poll(id=5, question="Question 5", pub_date=timezone.now()), ] self.data_with_excluded_fields = [ PollWithExcludeFields(id=1, question="Question 1", pub_date=timezone.now()), PollWithExcludeFields(id=2, question="Question 2", pub_date=timezone.now()), PollWithExcludeFields(id=3, question="Question 3", pub_date=timezone.now()), PollWithExcludeFields(id=4, question="Question 4", pub_date=timezone.now()), PollWithExcludeFields(id=5, question="Question 5", pub_date=timezone.now()), ] self.data_with_alternative_manager = [ PollWithAlternativeManager(id=1, question="Question 1", pub_date=timezone.now()), PollWithAlternativeManager(id=2, question="Question 2", pub_date=timezone.now()), PollWithAlternativeManager(id=3, question="Question 3", pub_date=timezone.now()), PollWithAlternativeManager(id=4, question="Question 4", pub_date=timezone.now()), PollWithAlternativeManager(id=5, question="Question 5", pub_date=timezone.now()), ] self.data_with_duplicates = [ PollWithUniqueQuestion(pk=1, question="Question 1", pub_date=timezone.now()), PollWithUniqueQuestion(pk=2, question="Question 2", pub_date=timezone.now()), PollWithUniqueQuestion(pk=3, question="Question 1", pub_date=timezone.now()), ]
def post(self, request, *args, **kwargs): poll_info_list = [ {"question": "1", "pub_date": date(2020, 1, 1)}, {"question": "2", "pub_date": date(2020, 1, 2)}, ] polls_to_create = [Poll(**poll_info) for poll_info in poll_info_list] bulk_create_with_history(polls_to_create, Poll) return HttpResponse(status=200)
def post(self, request, *args, **kwargs): default_user = CustomUser.objects.create_superuser( "test_user", "*****@*****.**", "pass" ) # Bulk create objects with history poll_info_list = [ {"question": "1", "pub_date": date(2020, 1, 1)}, {"question": "2", "pub_date": date(2020, 1, 2)}, ] polls_to_create = [Poll(**poll_info) for poll_info in poll_info_list] bulk_create_with_history(polls_to_create, Poll, default_user=default_user) return HttpResponse(status=200)