def new_todo(request, api_key): print("*"*200) print(request.POST) print("*"*200) todo = request.POST['title'] if todo: user = User.objects.get(userprofile__api_key=api_key) new_todo = ToDo(title=todo) new_todo.user = user new_todo.save() task = { 'todo' : new_todo.title, 'user' : user.username } return JsonResponse(task) return JsonResponse({error: "FAILED"})
# for num in range(1,5): # new_task = ToDo(title=fake.sentence()) # new_task.user = ken[0] # new_task.save() #Create random users for num in range(0, 20): user = User.objects.get_or_create(username=fake.user_name()) profile = UserProfile() profile.user = user[0] profile.api_key = hashlib.md5((user[0].username + str(datetime.now())).encode('utf-8')).hexdigest() profile.save() users.append(user) #Create and assign tasks for random people # for num in range(0, len(users)): # new_task = ToDo(title=fake.sentence()) # new_task.user = users[randint(0, len(users)-1)][0] # if num % 2 == 0: # new_task.completed = True # new_task.save() # todos.append(new_task) # create random tasks for num in range(0, 20): new_task = ToDo(title=fake.sentence()) new_task.user = users[randint(0, len(users)-1)][0] if num % 2 == 0: new_task.completed = True new_task.save() # todos.append(new_task)