mardi 14 juin 2016

Best practice to design django forms for CRUD operations


I am building a django web application for admin which mainly involves CRUD (create,read, update and delete) operations. I need suggestions/best practices to design the forms. I am new to django and python and need experts suggestions. Currently I have created different methods in the views like

def create(request):
    --logic to add
     return HttpResponseRedirect('/createproduct')

def delete(request,obj_id):                
    result=products.objects.get(product_type=object_id).delete()                              
    return HttpResponseRedirect('/listobjects/')

def getObjects(request):
    products= products.objects.order_by('product_type')
    return render(request,'getProducts.html',
                {'results': products})

and my urls.py is like below

url(r'^createproduct/$',create),
url(r'^listobjects/',getObjects),
url(r'^deleteproduct/(?P<object_id>d+)/$',delete)

Aucun commentaire:

Enregistrer un commentaire