I have a 2drop down list and 1 description box i want to save the data from all this to my postgresql data base

18 views
Skip to first unread message

neha bhurke

unread,
Feb 17, 2021, 4:08:51 AM2/17/21
to Django users
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})

itmind club

unread,
Feb 17, 2021, 7:15:55 PM2/17/21
to django...@googlegroups.com
SAME ISSUE WITH ME


--
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 django-users...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/3a1fda33-6ba6-46db-a8a5-806074cf6f25n%40googlegroups.com.
Reply all
Reply to author
Forward
Message has been deleted
0 new messages