from django.shortcuts import renderfrom saeed.forms import SmodelForm from saeed.models import Smodelfrom django.shortcuts import render, redirect
# Create your views here.def emp(request): if request.method == "POST": form = SmodelForm(request.POST) if form.is_valid(): try: form.save() return redirect('/show') except AssertionError as error: print(error) pass
else: form = SmodelForm() return render(request,'saeed/index.html',{'form':form}) #----------------------------------------def show(request): smodels = Smodel.objects.all() return render(request,'saeed/show.html',{'smodels':smodels}) #----------------------------------------
def edit(request, id): smodels = Smodel.objects.get(id=id) return render(request,'saeed/edit.html', {'smodels':smodels}) #-------------------------------------------
def update(request, id): smodels = Smodel.objects.get(id=id) form = SmodelForm(request.POST, instance = smodels) if form.is_valid(): form.save() return redirect("/show") return render(request,'saeed/edit.html',{'smodels':smodels})
#---------------------------------------------def destroy(request, id): smodels = Smodel.objects.get(id=id) smodels.delete() return redirect("/show")
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>Index</title> {% load staticfiles %} {% load bootstrap4 %} <link rel="stylesheet" href="{% static 'css/style.css' %}"/> </head> <body> <form method="POST" class="post-form" action="/update/{{employee.id}}"> {% csrf_token %} <div class="container"> <br> <div class="form-group row"> <label class="col-sm-1 col-form-label"></label> <div class="col-sm-4"> <h3>Update Details</h3> </div> </div> <div class="form-group row"> <label class="col-sm-2 col-form-label">User Id:</label> <div class="col-sm-4"> <input type="number" name="eid" id="id_eid" required maxlength="8" value="{{ saeed.eid }}"/> </div> </div> <div class="form-group row"> <label class="col-sm-2 col-form-label">User Name:</label> <div class="col-sm-4"> <input type="text" name="elogin" id="id_elogin" required maxlength="8" value="{{ saeed.elogin }}" /> </div> </div> <div class="form-group row"> <label class="col-sm-2 col-form-label">User Password:</label> <div class="col-sm-4"> <input type="email" name="epassword" id="id_password" required maxlength="254" value="{{ saeed.password }}" /> </div> </div> <div class="form-group row"> <label class="col-sm-2 col-form-label">Like A Day:</label> <div class="col-sm-4"> <input type="number" name="elikeday" id="id_elikeday" required maxlength="999" value="{{ saeed.elikeday}}" /> </div> </div> <div class="form-group row"> <label class="col-sm-1 col-form-label"></label> <div class="col-sm-4"> <button type="submit" class="btn btn-success">Update</button> </div> </div> <div class="form-group row"> <label class="col-sm-2 col-form-label">Follow per Day:</label> <div class="col-sm-4"> <input type="number" name="efollowperday" id="id_efollowperday" required maxlength="999" value="{{ saeed.efollowperday}}" /> </div> </div> </form> </body> </html>
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>Index</title> {% load staticfiles %} {% load bootstrap4 %} <link rel="stylesheet" href="{% static 'css/style.css' %}"/> </head> <body> <form method="POST" class="post-form" action="/emp"> {% csrf_token %} <div class="container"> <br> <div class="form-group row"> <label class="col-sm-1 col-form-label"></label> <div class="col-sm-4"> <h3>Enter Details</h3> </div> </div> <div class="form-group row"> <label class="col-sm-2 col-form-label">User Id:</label> <div class="col-sm-4"> {{ form.eid }} </div> </div> <div class="form-group row"> <label class="col-sm-2 col-form-label">User Login:</label> <div class="col-sm-4"> {{ form.elogin }} </div> </div> <div class="form-group row"> <label class="col-sm-2 col-form-label">User password:</label> <div class="col-sm-4"> {{ form.epassword }} </div> </div> <div class="form-group row"> <label class="col-sm-2 col-form-label">Lika A day:</label> <div class="col-sm-4"> {{ form.elikeDay }} </div> </div> <div class="form-group row"> <label class="col-sm-2 col-form-label">User follow per day:</label> <div class="col-sm-4"> {{ form.efollowPerDay }} </div> </div>
<div class="form-group row"> <label class="col-sm-1 col-form-label"></label> <div class="col-sm-4"> <button type="submit" class="btn btn-primary">Submit</button> </div> </div> </div> </form> </body> </html>
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>Index</title> {% load staticfiles %} {% load bootstrap4 %} <link rel="stylesheet" href="{% static 'css/style.css' %}"/> </head> <body> <form method="POST" class="post-form" action="/emp"> {% csrf_token %} <div class="container"> <br> <div class="form-group row"> <label class="col-sm-1 col-form-label"></label> <div class="col-sm-4"> <h3>Enter Details</h3> </div> </div> <div class="form-group row"> <label class="col-sm-2 col-form-label">User Id:</label> <div class="col-sm-4"> {{ form.eid }} </div> </div> <div class="form-group row"> <label class="col-sm-2 col-form-label">User Login:</label> <div class="col-sm-4"> {{ form.elogin }} </div> </div> <div class="form-group row"> <label class="col-sm-2 col-form-label">User password:</label> <div class="col-sm-4"> {{ form.epassword }} </div> </div> <div class="form-group row"> <label class="col-sm-2 col-form-label">Lika A day:</label> <div class="col-sm-4"> {{ form.elikeDay }} </div> </div> <div class="form-group row"> <label class="col-sm-2 col-form-label">User follow per day:</label> <div class="col-sm-4"> {{ form.efollowPerDay }} </div> </div>
<div class="form-group row"> <label class="col-sm-1 col-form-label"></label> <div class="col-sm-4"> <button type="submit" class="btn btn-primary">Submit</button> </div> </div> </div> </form> </body> </html>
from django import forms from saeed.models import Smodel
class SmodelForm(forms.ModelForm): class Meta: model = Smodel fields = "__all__"
from django.db import modelsfrom django.conf import settings
# Create your models here.class Smodel(models.Model):
eid=models.AutoField(primary_key=True) # eid=models.IntegerField(default=0) elogin = models.CharField(max_length=8) epassword= models.CharField(max_length=8) elikeDay=models.IntegerField(default=10) efollowPerDay=models.IntegerField(default=10)
#esession = models.TextField() class Meta: db_table = "saeed" """Definition of urls for bot3."""from django.conf.urls import include, urlfrom django.contrib import admin from django.urls import path from saeed import views
# Uncomment the next two lines to enable the admin:# from django.contrib import admin# admin.autodiscover()
urlpatterns = [ # path('', admin.site.urls, name='admin'), path('', views.show, name='index'), path('', views.emp, name='emp'), path('', views.show, name='show'), path('', views.show, name='index'),
# path('', views.emp, name='show'), # path('', views.emp, name='index'),
# path('index', views.show), # path('admin/', admin.site.urls), path('emp', views.emp), path('show',views.show), # path('index', views.emp),
path('edit/<int:id>', views.edit, name='edit'), path('update/<int:id>', views.update, name='update'), path('delete/<int:id>', views.destroy, name='delete'),]