Created
June 29, 2019 07:56
-
-
Save aballah-chamakh/b85d91d62e9fc1abe551e7eb7a80e2cd to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from django.shortcuts import render | |
from .models import Product | |
from .forms import PorductForm | |
# function based views | |
def product_detail_view(request,id): | |
product_obj = Product.objects.get(id=id) | |
context = {'product_obj':product_obj} | |
return render(request,'product_detail.html',context) | |
def product_list_view(request,id): | |
product_qs = Product.objects.all() | |
context = {'product_obj':product_qs} | |
return render(request,'product_list.html',context) | |
def product_create_view(request): | |
form = ProductForm(request.POST or None) | |
if form.is_valid(): | |
form.save() | |
return redirect('/') | |
context = {'form': form} | |
return render(request, "product_create.html", context) | |
def product_update_view(request,id): | |
product_obj = Product.objects.get(id=id) | |
form = ProductForm(requets.POST or None,instance=product_obj) | |
if form.is_valid() : | |
form.save() | |
return redirect('/') | |
context = {'form':form} | |
return render(request,"product_update.html",context) | |
def product_delete_view(request,id): | |
product_obj = Product.objects.get(id=id) | |
if request.methode == 'POST' : | |
product_obj.delete() | |
return redirect('/') | |
context = {'product_obj':product_obj} | |
return render(request,'product_delete.html',context) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment