SAME ISSUE WITH ME
On Wed, Feb 17, 2021 at 2:09 PM neha bhurke <[email protected]> wrote: > Hii Everyone, > > I have created a form with 2dropdown list , 1 description box and 1 > datetime field but data is not saved in the database. I am getting problem > due to date can anyone help me please.. > > This is my models.py > > class data(models.Model): > machinename = models.CharField(max_length=100) > activity = models.CharField(max_length=255) > description = models.CharField(max_length=500) > datetime = models.DateTimeField() > > > This is my form (html) > > {% extends 'main.html' %} > {% load static %} > > <html> > <head> > <meta name="viewport" content="width=device-width, initial-scale=1"> > > > </head> > > {% block content %} > <body bgcolor="white"> > > > > <link rel="stylesheet" href="{% static "css/newform.css" %}"> > > <form name="form" action="newdata" method="POST"> > {% csrf_token %} > {{MyDataform.as_p}} > <br><br> > <select name="machinename" id="machinename"> > <optgroup label="machinename"> > {% for results in data%} > <option>{{results.machinename}}</option> > > {%endfor%} > </optgroup> > </select> > <br> > <br> > <select name="activity" id="activity"> > <optgroup label="activity"> > <option> Idle </option> > <option> Under batch process </option> > <option> Under breakdown </option> > <option> Breakdown raised </option> > <option> Breakdown closed </option> > <option> Under maintenance </option> > <option> Change control raised </option> > <option> Change control closed </option> > </optgroup> > </select> > <br> > <mainlabel> description: </mainlabel><br> > <input type="textarea" placeholder="Enter description" name="description" > required><br> > > <br> > > <input type="datetime-local" required autocomplete="off" name="date" /> > <br> > <br> > <button type="submit" class="button">SaveDetails</button> > > > </form> > > > {% endblock content %} > </body> > > > This is my form.py > > class Dataform(forms.ModelForm): > class Meta: > model = data > fields = "__all__" > > This is my views.py > > def newdata(request): > if request.method == "POST": > MyDataform = Dataform(request.POST) > if MyDataform.is_valid(): > MyDataform.save() > results = machinelist.objects.all() > #result = data.objects.all() > return redirect('/', {'data': results}) > else: > MyDataform=Dataform() > results = machinelist.objects.all() > result = data.objects.all() > return redirect('/',{'data': results},{'record':result}) > else: > results = machinelist.objects.all() > result = data.objects.all() > return redirect('/', {'data': results},{'record':result}) > > -- > 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 view this discussion on the web visit > https://groups.google.com/d/msgid/django-users/3a1fda33-6ba6-46db-a8a5-806074cf6f25n%40googlegroups.com > <https://groups.google.com/d/msgid/django-users/3a1fda33-6ba6-46db-a8a5-806074cf6f25n%40googlegroups.com?utm_medium=email&utm_source=footer> > . > -- 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 view this discussion on the web visit https://groups.google.com/d/msgid/django-users/CAOWKeteJEoxEpRrp%2Bwjr8OBcvrA-6nMNtZpMg9ANiYkM67T77w%40mail.gmail.com.

