I am using mysql database with my project, and made a user input form
with submit button. After submitting the form, it produces an html
output, If i again reload the output page it fills a duplicate entry
in the database. And on every refresh, it continues to add entries in
the database.
How will i prevent these duplicate entries on refreshing.
Here is the views of my code related to that form:
def header(request):
if request.method=='POST':
form = headForm(request.POST)
if form.is_valid():
cd = form.cleaned_data
form.save()
zee = head.objects.aggregate(Max('id'))
mee =zee['id__max']
Head = head.objects.filter(id = mee)
return render_to_response('report/header.html',
{'Head':Head,},context_instance=RequestContext(request))
else:
form = headForm()
return render_to_response('report/report.html', {"form":form},
context_instance=RequestContext(request))
And the models are described as:
class head(models.Model):
refrence_no = models.CharField(max_length=255) #college
reference letter no.
dispatch_report_date = models.CharField(max_length=255) #report
dispatch date, to the client
date_of_testing = models.CharField(max_length=255) #date on
which test is performed
subject = models.CharField(max_length=255)
reference = models.CharField(max_length=255) #client reference letter no.
column_1 = models.CharField(max_length=255,blank=True)
column_2 = models.CharField(max_length=255,blank=True)
column_3 = models.CharField(max_length=255,blank=True)
def __str__(self):
return self.subject
class headForm(ModelForm):
class Meta :
model = head
Thanks in advance.
--
Satinderpal Singh
http://satindergoraya.blogspot.in/
http://satindergoraya91.blogspot.in/
--
You received this message because you are subscribed to the Google Groups "Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to django-users+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment