Hi, required attribute works in forms, not in models. For models fields that are not required in forms you need to use blank=True.
Though that's not the right solution. Why are you including "completed" field in a form (which you validate for user input) if you are not going to have such a input (checkbox) in a form? On Sun, Apr 21, 2019 at 3:02 PM Sipum Mishra <[email protected]> wrote: > if i do changes as above in model then it throws error like - > > class List(models.Model): > File "F:\django\to_do_list\todo\models.py", line 6, in List > completed = models.BooleanField(required=False) > TypeError: __init__() got an unexpected keyword argument 'required' > > > On Sun, 21 Apr 2019 at 17:27, Sipum Mishra <[email protected]> wrote: > >> Jani, Do you mean I need to change completed field in model like as below >> ? >> >> completed = models.BooleanField(default=False,required=False) >> >> On Sun, 21 Apr 2019 at 17:23, Sipum Mishra <[email protected]> wrote: >> >>> Hi Jani, >>> form.errors gives error as - >>> >>> <ul class="errorlist"><li>item<ul class="errorlist"><li>This field is >>> required.< >>> /li></ul></li></ul> >>> >>> can u plz tell me where i did wrong? >>> >>> On Sun, 21 Apr 2019 at 16:43, Jani Tiainen <[email protected]> wrote: >>> >>>> completed is a required field and you're not passing any value with it. >>>> If you print form.errors you would should see that it complains about >>>> "completed" "this field is required" >>>> >>>> Note that providing default value in a model is not same as making >>>> field optional. >>>> >>>> On Fri, Apr 19, 2019 at 2:05 PM Sipum Mishra <[email protected]> wrote: >>>> >>>>> Hi All, >>>>> >>>>> I am always getting - form.is_valid returning False. kindly check >>>>> where I am doing wrong. >>>>> please find below code. >>>>> >>>>> >>>>> views.py >>>>> ----------- >>>>> def home(request): >>>>> >>>>> if request.method == 'POST': >>>>> form = ListForm(request.POST or None) >>>>> print(form.is_valid(), "-->",request.POST['Item']) >>>>> print(form.errors) >>>>> print(form) >>>>> if form.is_valid(): >>>>> form.save() >>>>> all_items = List.objects.all >>>>> messages.success(request, ('Item has been Added to the List!')) >>>>> return render(request,'home.html', {'all_items' : all_items}) >>>>> else: >>>>> print("deba-->",request.POST) >>>>> return HttpResponse("Form is invalid!") >>>>> else: >>>>> all_items = List.objects.all >>>>> return render(request,'home.html', {'all_items' : all_items}) >>>>> >>>>> ------------- >>>>> form.py >>>>> ------------- >>>>> >>>>> class ListForm(forms.ModelForm): >>>>> class Meta: >>>>> model = List >>>>> fields = ["item", "completed"] >>>>> >>>>> >>>>> -------------------- >>>>> model.py >>>>> --------------------- >>>>> >>>>> class List(models.Model): >>>>> item = models.CharField(max_length=200) >>>>> completed = models.BooleanField(default=False) >>>>> >>>>> >>>>> def __str__(self): >>>>> return self.item + '|' + str(self.completed) >>>>> >>>>> -- >>>>> You received this message because you are subscribed to the Google >>>>> Groups "Django users" group. >>>>> To unsubscribe from this group and stop receiving emails from it, send >>>>> an email to [email protected]. >>>>> To post to this group, send email to [email protected]. >>>>> Visit this group at https://groups.google.com/group/django-users. >>>>> To view this discussion on the web visit >>>>> https://groups.google.com/d/msgid/django-users/4ca5e82d-f34b-4ab4-8f82-5be0dcdebecc%40googlegroups.com >>>>> <https://groups.google.com/d/msgid/django-users/4ca5e82d-f34b-4ab4-8f82-5be0dcdebecc%40googlegroups.com?utm_medium=email&utm_source=footer> >>>>> . >>>>> For more options, visit https://groups.google.com/d/optout. >>>>> >>>> >>>> >>>> -- >>>> Jani Tiainen >>>> Software wizard >>>> >>>> https://blog.jani.tiainen.cc/ >>>> >>>> Always open for short term jobs or contracts to work with Django. >>>> >>>> -- >>>> You received this message because you are subscribed to the Google >>>> Groups "Django users" group. >>>> To unsubscribe from this group and stop receiving emails from it, send >>>> an email to [email protected]. >>>> To post to this group, send email to [email protected]. >>>> Visit this group at https://groups.google.com/group/django-users. >>>> To view this discussion on the web visit >>>> https://groups.google.com/d/msgid/django-users/CAHn91of6O55rPh6fJFDHQ1Pc2v5Lk%3DT8JtN1wS_4NVuP9vi3MA%40mail.gmail.com >>>> <https://groups.google.com/d/msgid/django-users/CAHn91of6O55rPh6fJFDHQ1Pc2v5Lk%3DT8JtN1wS_4NVuP9vi3MA%40mail.gmail.com?utm_medium=email&utm_source=footer> >>>> . >>>> For more options, visit https://groups.google.com/d/optout. >>>> >>> -- > You received this message because you are subscribed to the Google Groups > "Django users" group. > To unsubscribe from this group and stop receiving emails from it, send an > email to [email protected]. > To post to this group, send email to [email protected]. > Visit this group at https://groups.google.com/group/django-users. > To view this discussion on the web visit > https://groups.google.com/d/msgid/django-users/CAGHZBzx5TL%2BNZ--kbY2XpypCdOf5YP0AikdrFDQQ-rgg1026ow%40mail.gmail.com > <https://groups.google.com/d/msgid/django-users/CAGHZBzx5TL%2BNZ--kbY2XpypCdOf5YP0AikdrFDQQ-rgg1026ow%40mail.gmail.com?utm_medium=email&utm_source=footer> > . > For more options, visit https://groups.google.com/d/optout. > -- Jani Tiainen Software wizard https://blog.jani.tiainen.cc/ Always open for short term jobs or contracts to work with Django. -- You received this message because you are subscribed to the Google Groups "Django users" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To post to this group, send email to [email protected]. Visit this group at https://groups.google.com/group/django-users. To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/CAHn91ofYQf19hbWh39NQjXMRzHo_D-Ta2U%2BT2TjEzLXdAQs09g%40mail.gmail.com. For more options, visit https://groups.google.com/d/optout.

