Django1.8.6+Python3.4.3实践点滴——Forms

 1 from django import forms
 2 from django.forms import ModelForm
 3 from expressway.app.system_admin.models import Device_Type,Admin_Records
 4 from expressway.app.accounts.user import User
 5 from expressway.app.accounts.site import Site
 6 class Deivce_TypeForm(ModelForm):
 7     name = forms.CharField(label='设备类型',widget=forms.TextInput(attrs={'class':'form-control ',
 8     'placeholder':"请输入需要添加的设备类型",'size':'50%'}))
 9     class Meta:
10         model = Device_Type
11         fields = '__all__'
12 
13 class Admin_RecordsForm(ModelForm):
14     notification_date = forms.DateField(label='通知时间',widget=forms.TextInput(attrs={'class':'form-control',
15     'placeholder':"格式为:2016/01/01",'size':'20%'}))
16     notification_person = forms.ModelChoiceField(queryset=User.objects.all(),label="通知人员",widget=forms.Select(
17             attrs={'class':'form-control','style':'width:180px'}))
18     fault_place = forms.ModelChoiceField(queryset=Site.objects.all(),label='故障地点',widget=forms.Select(attrs={
19         'class':'form-control','style':'width:180px'}))
20     device_type = forms.ModelChoiceField(queryset=Device_Type.objects.all(),label='设备类型',widget=forms.Select(attrs={
21         'class':'form-control','style':'width:180px'}))
22     fault_depict = forms.CharField(label='故障现象',widget=forms.TextInput(attrs={'class':'form-control ',
23     'placeholder':"请输入故障描述",'size':'145%'}))
24     diapose_mode = forms.CharField(label='处理方式',widget=forms.TextInput(attrs={'class':'form-control ',
25     'placeholder':"请输入处理方式",'size':'145%'}))
26     repair_result = forms.CharField(label='维修结果',widget=forms.TextInput(attrs={'class':'form-control',
27     'placeholder':"维修结果",'size':'20%'}))
28     repair_person = forms.CharField(label='维修人员',widget=forms.TextInput(attrs={'class':'form-control',
29     'placeholder':"维修人员",'size':'20%'}))
30     repair_date = forms.DateField(label='维修时间',widget=forms.TextInput(attrs={'class':'form-control',
31     'placeholder':"格式为:2016/01/01",'size':'20%'}))
32     records_person = forms.CharField(label='记录人员',widget=forms.TextInput(attrs={'class':'form-control',
33     'placeholder':"记录人员",'size':'20%'}))
34     
35     class Meta:
36         model = Admin_Records
37         fields = '__all__'

1、本次练习了模型创建表单ModelChoiceField的使用,参考官方文档

2、练习使用了widget使用

你可能感兴趣的:(Django1.8.6+Python3.4.3实践点滴——Forms)