You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
33 lines
926 B
33 lines
926 B
6 months ago
|
from django.shortcuts import render, redirect
|
||
|
from app01 import models
|
||
|
from app01.utils.bootstrap import BootStrapModelForm
|
||
|
|
||
|
|
||
|
def city_list(request):
|
||
|
queryset = models.City.objects.all()
|
||
|
return render(request, 'city_list.html', {'queryset': queryset})
|
||
|
|
||
|
|
||
|
class UpModelForm(BootStrapModelForm):
|
||
|
bootstrap_exclude_fields = ['img']
|
||
|
|
||
|
class Meta:
|
||
|
model = models.City
|
||
|
fields = "__all__"
|
||
|
|
||
|
|
||
|
def city_add(request):
|
||
|
title = "新建城市"
|
||
|
|
||
|
if request.method == "GET":
|
||
|
form = UpModelForm()
|
||
|
return render(request, 'upload_form.html', {"form": form, 'title': title})
|
||
|
|
||
|
form = UpModelForm(data=request.POST, files=request.FILES)
|
||
|
if form.is_valid():
|
||
|
# 对于文件:自动保存;
|
||
|
# 字段 + 上传路径写入到数据库
|
||
|
form.save()
|
||
|
return redirect("/city/list/")
|
||
|
return render(request, 'upload_form.html', {"form": form, 'title': title})
|