Exemple #1
0
def new_list(request):
    #print(request.POST)
    form = ItemForm(data=request.POST)
    if form.is_valid():
        list_ = List()
        if request.user.is_authenticated:
            list_.owner = request.user
        list_.save()
        #list_ = List.objects.create()
        form.save_custom(for_list=list_)
        return redirect(f'{settings.BASE_URL}/lists/{list_.id}/')
    else:
        return render(request, 'home.html', {
            "form": form,
            'error': ITEM_EMPTY_ERROR
        })
Exemple #2
0
 def test_form_save_handles_saving_to_a_list(self):
     list_ = List.objects.create()
     form = ItemForm(data={'text': 'do me'})
     new_item = form.save_custom(for_list=list_)
     self.assertEqual(new_item, Item.objects.first())
     self.assertEqual(new_item.text, 'do me')
     self.assertEqual(new_item.list, list_)