from django import forms
from .models import userTrade
class OrderCreateForm(forms.ModelForm):
class Meta:
model = orderItem
fields = ( "deliveryDate"
,"deliveryDateSub"
,"supplier"
,"item"
,"size"
,"quantity"
,"purchasePrice"
,"sellingPrice"
,"profit"
,"remarks")
widgets = {
'deliveryDate': forms.DateInput(attrs={'type': 'date'}),
'deliveryDateSub': forms.DateInput(attrs={'type': 'date'}),
'supplier': forms.Select(attrs={
'class': 'form-control'
}),
'item': forms.Select(attrs={
'class': 'form-control'
}),
'size': forms.TextInput(attrs={
'class': 'form-control'
}),
'quantity': forms.TextInput(attrs={
'class': 'form-control'
}),
'purchasePrice': forms.TextInput(attrs={
'class': 'form-control'
}),
'sellingPrice': forms.TextInput(attrs={
'class': 'form-control'
}),
'profit': forms.TextInput(attrs={
'class': 'form-control'
}),
'remarks': forms.TextInput(attrs={
'class': 'form-control'
}),
}
labels = {
'deliveryDate':'納入日'
,'deliveryDateSub':'納入日(変更)'
,'supplier':'仕入先'
,'item':'商品'
,'size':'規格'
,'quantity':'数量'
,'purchasePrice':'仕入値'
,'sellingPrice':'売値'
,'profit':'利益'
,'remarks':'備考'
}
class UserCreateForm(forms.ModelForm):
class Meta:
model = userTrade
fields = ("name", "remarks")
widgets = {
"name": forms.TextInput(attrs={"class": "form-control"}),
"remarks": forms.TextInput(attrs={"class": "form-control"}),
}
labels = {
"name": "ユーザー名",
"remarks": "備考",
}
# formから値を取得(submit後に呼び出される)
def clean(self):
# 値を取得
data = super().clean()
name = data.get("name")
remarks = data.get("remarks")
# 文字数が0の場合
if len(name) == 0:
msg = "ユーザー名は0文字以上"
# エラーを表示
self.add_error("name", msg)
# 文字数が20以上の場合
if len(name) >= 20:
msg = "ユーザー名は20文字以下"
# エラーを表示
self.add_error("name", msg)