first commit

This commit is contained in:
2026-02-22 12:29:18 +05:00
commit d34447d322
40 changed files with 585 additions and 0 deletions

37
autoapp/forms.py Normal file
View File

@@ -0,0 +1,37 @@
from django import forms
from .models import Auto
class AutoForm(forms.ModelForm):
class Meta:
model = Auto
fields = ['brand', 'model', 'year', 'color']
# Настройка виджетов и стилей (опционально, но улучшает внешний вид)
widgets = {
'brand': forms.TextInput(attrs={
'class': 'form-control',
'placeholder': 'Например: Toyota, BMW, Lada'
}),
'model': forms.TextInput(attrs={
'class': 'form-control',
'placeholder': 'Например: Camry, X5, Granta'
}),
'year': forms.NumberInput(attrs={
'class': 'form-control',
'placeholder': 'Год выпуска (например, 2023)',
'min': 1900,
'max': 2100,
}),
'color': forms.TextInput(attrs={
'class': 'form-control',
'placeholder': 'Например: чёрный, серебристый, красный'
}),
}
# Дополнительная валидация (опционально)
def clean_year(self):
year = self.cleaned_data.get('year')
if year and (year < 1900 or year > 2100):
raise forms.ValidationError("Год выпуска должен быть в разумных пределах (19002100)")
return year