On Friday, March 18, 2011 2:08:02 AM UTC, django beginner wrote: > > Hi Django users, > > I am having some dilemma over converting simple admin page *Template*(without > having to use the built in django-admin functionality) by using > forms, and not templates, I have the following sample Admin page that allows > users to add, edit and delete record per row* to Forms*: (Edit and Delete > will be links that will be directed to designated forms) > > *table.html:* (/timetable) > > *Booking ID Golf Club Status * > 1 Country Golf Pending Edit Delete > 2 Pacific Harbour Cancelled Edit Delete > 3 Pacific Dunes Booked Edit Delete > 4 Peninsula Booked Edit Delete > ----------------------- > *Model:* > class Booking(models.Model): > bookingId = models.AutoField(primary_key=True) > golfClubName = models.CharField(max_length=50) > status = models.CharField(max_length=20) > > * > views.py* > def book_tee_delete(request, object_id): > conn = psycopg2.connect("dbname=my_db user=postgres password=sa > host=localhost") > cur = conn.cursor() > sql = "delete from booking where bookingId = '%s'"% (object_id) > cur.execute(sql) > conn.commit() > conn.close() > return HttpResponseRedirect("/timetable") > > def edit_book_tee(request, object_id, model): > booking = Booking.objects.get(pk=int(object_id)) > template_name = 'edit_form.html' > t = loader.get_template(template_name) > c = RequestContext(request, {"obj": booking, "id":object_id}) > return HttpResponse(t.render(c)) > > def save_edit(request): > time_format = "%Y-%m-%d %H:%M" > if request.POST['submit'] == 'Save': > bookingid = request.POST['id'] > golfclubname = request.POST['golfclubname1'] > status = request.POST['status1'] > conn = psycopg2.connect("dbname=my_db user=postgres password=sa > host=localhost") > cur = conn.cursor() > sql = "UPDATE booking SET golfClubName='%s', status='%s WHERE > bookingId='%s'" %(golfclubname,status,bookingid) > cur.execute(sql) > conn.commit() > conn.close() > else: #for delete > bookingid = request.POST['id'] > conn = psycopg2.connect("dbname=my_db user=postgres password=sa > host=localhost") > cur = conn.cursor() > sql = "delete from chasingbirdies_booking where bookingId = '%s'" % > (bookingid) > cur.execute(sql) > conn.commit() > conn.close() > return HttpResponseRedirect("/timetable") > <snip> > My question would be, how do I transform templates on the Edit/Delete link > into Forms, (my other question would be, is there any way I could show my > css using templates on Edit?)? > Thanks in advance!
This doesn't make sense either. What do you mean, "transform templates into forms"? If you want a form on the edit link, then create one in the view and pass it to the template. Also, why on earth are you using raw SQL in your update/delete views? You're not doing anything complicated, you should be doing all of that via the ORM. *Especially* as the way you have done it leaves you wide open to SQL injection attacks. -- DR. -- 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+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.