==================================Subject===========================
一.forms.py
from django import forms
class EditForm(forms.Form):
name=forms.CharField(required=True)
amount=forms.IntegerField(required=True)
days=forms.CharField(required=True)
number=forms.CharField(required=True)
assurance=forms.CharField(required=True)
remark=forms.CharField()
class AddForm(forms.Form):
name = forms.CharField(required=True)
amount = forms.IntegerField(required=True)
days = forms.CharField(required=True)
number = forms.CharField(required=True)
assurance = forms.CharField(required=True)
remark = forms.CharField()
二.models.py
from django.db import models
# Create your models here.
class Subject(models.Model):
name=models.CharField(max_length=20,null=False,verbose_name='学科名称')
number=models.IntegerField(null=False)
days=models.IntegerField(null=False,verbose_name='学时')
amount=models.DecimalField(max_digits=10,decimal_places=0,null=False,verbose_name='学费')
assurance=models.CharField(max_length=255,verbose_name='承诺')
remark=models.CharField(max_length=255,verbose_name='备注')
status=models.IntegerField(null=False,default=0)
creater=models.IntegerField(null=False,default=0)
create_time=models.DateTimeField(auto_now_add=True,null=False)
updater=models.IntegerField(null=True)
update_time=models.DateTimeField(auto_now_add=True,null=True)
class Meta:
db_table='subject'
三.urls.py
from django.conf.urls import url
from .views import IndexView,DetailView,EditView,DeleteView,AddView
urlpatterns=[
url(r'^$',IndexView.as_view(),name='index'),
url(r'^detail/(?P<id>\d+)',DetailView.as_view(),name='detail'),
url(r'^edit/',EditView.as_view(),name='edit'),
url(r'^delete/(?P<id>\d+)',DeleteView.as_view(),name='delete'),
url(r'^add/',AddView.as_view(),name='add')
]
四.views.py
from django.shortcuts import render, HttpResponse, redirect
# Create your views here.
from django.views import View
from .models import Subject
from .forms import EditForm,AddForm
class IndexView(View):
def get(self, request):
rs = Subject.objects.all()
return render(request, 'sub_list.html', {"subjects": rs})
def post(self, request):
pass
class DetailView(View):
def get(self, request, id):
rs = Subject.objects.get(id=id)
return render(request, 'sub_detail.html', {"info": rs})
def post(self, request):
pass
class EditView(View):
def get(self, request):
id = request.GET.get('id')
rs = Subject.objects.get(id=id)
return render(request, 'sub_edit.html', {"info