Last active
June 5, 2021 16:16
-
-
Save siumhossain/9a9055bc5fe1977d806fedc6c16492e9 to your computer and use it in GitHub Desktop.
django crud view
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
| def lead_create(request): | |
| form = LeadForm() | |
| if request.method == 'POST': | |
| form = LeadForm(request.POST) | |
| if form.is_valid(): | |
| form.save() | |
| return redirect('/lead') | |
| context = { | |
| 'form':form | |
| } | |
| return render(request,'lead_create.html',context) |
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
| def lead_delete(request,pk): | |
| lead = Lead.objects.get(id=pk) | |
| lead.delete() | |
| return redirect('/lead') |
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
| def lead_details(request,pk): | |
| lead = Lead.objects.get(id=pk) | |
| context = {'lead': lead } | |
| return render(request,'lead_details.html',context) |
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
| def lead_update(request,pk): | |
| lead = Lead.objects.get(id=pk) | |
| form = LeadForm(instance=lead) | |
| if request.method == 'POST': | |
| form = LeadForm(request.POST,instance=lead) | |
| if form.is_valid(): | |
| form.save() | |
| return redirect('/lead') | |
| context = { | |
| 'form':form, | |
| 'lead':lead | |
| } | |
| return render(request,'lead_create.html',context) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment