Django 模型

Django modelforms

我是 Django 的新手,我需要一些帮助。所以我试图更改我项目中的标签名称,但它不起作用我尝试了不同的方式,这是最后一个:

from django import forms
from django.utils.translation import ugettext_lazy as _
from Upload_Page.models import Form_Data

class Upload_Document(forms.ModelForm):
     class Meta:

           model= Form_Data
           fields =['title','author','document_type','keywords','abstract','authentication','site','comments','file_upload']
           widgets = {
               'title' : forms.TextInput(attrs={
                   'class':'title_class',
                   'placeholder':'Insert title here',
                   'label':'Tit'


               })

}

这是型号:

# Create your models here.
class Form_Data(models.Model):
    title=models.CharField(unique=True,max_length=100,blank=False)
    author=models.CharField(max_length=100)
    document_type=models.CharField(choices=DOCUMENT_TYPES,max_length=500,blank=False,default=None)
    keywords=models.CharField(max_length=500)
    abstract=models.TextField(null=True,blank=True)
    authentication=models.CharField(choices=DOCUMENT_AUTHENTICATION_LEVEL,unique=True,blank=False,default=None,max_length=500)
    site=models.URLField(unique=True,blank=True)
    comments=models.TextField(null=True,blank=True)
    file_upload=models.FileField(default=None)


    def __str__(self):
        return self.title
    
class Authentication_Level(models.Model):
    title=models.ForeignKey('Form_Data',to_field='title', on_delete=models.CASCADE,related_name='title1')
    authentication=models.ForeignKey('Form_Data',to_field='authentication', on_delete=models.CASCADE, related_name="authenticationlevel")
    download_rights=models.CharField(max_length=500)
    
    
    def __str__(self):
        return self

这是我的观点:

from django.shortcuts import render
from django.views.generic import View
from Upload_Page import models
from django.core.files.storage import FileSystemStorage
from Upload_Page.forms import Upload_Document
from django.shortcuts import redirect



def upload_doc(request):
  if request.method == 'POST':
    form = Upload_Document(request.POST, request.FILES)
    if form.is_valid():
      form.save()
      return redirect('home_page:homepageview')
  
  else:
    form = Upload_Document(auto_id=True,label_suffix='')
  return render(request, 'Upload_Page/upload_page.html', {'form':form})

我还想对齐输入字段头部的标签,我该怎么做? 提前谢谢你

class Upload_Document(forms.ModelForm):
    class Meta:
        model = Form_data

        labels = {
                "title": "Insert Desired Label Here",
                "author": "Insert Desired Label Here",
                "document_type": "Insert Desired Label Here",
                 // etc etc etc...
        }

        fields = ['title', 'author', 'document_type'] // etc etc etc...


 // To align things you can use css in the widgets section:
       
        widgets = {
                'document_type': forms.Textarea(attrs={'style': 'vertical-align: text-top'}),
        }