这是一个令人尴尬的简单问题。我试图了解如何在我正在构建的第一个Django应用程序中包含一个简单的Python函数。这是我的views.py文件...如何在Django中编写Python代码
from django.shortcuts import render
from noticeboard.models import Listings
from django.views import generic
from django.template import Context
class IndexView(generic.ListView):
template_name = 'listings/index.html'
context_object_name = 'latest_listings'
def get_queryset(self):
return Listings.objects.order_by('-pub_date')
class DetailView(generic.DetailView):
model = Listings
template_name = 'listings/listings_detail.html'
context_object_name = 'listing'
在信息模型中,我有以下领域:
listing = models.CharField(max_length=50)
我想编写一个函数,确保上市变量是所有上案例 - 我知道如何编写函数 - 我只是不知道如何将它整合到views.py文件中!
你说你想“确保列表变量都是大写” - 你的意思是你打算接受输入并希望在保存之前将其大写?您在此处使用的视图处理显示数据库中已存在的信息,但不处理创建或更新。 –