-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathforms.py
More file actions
80 lines (77 loc) · 2.58 KB
/
Copy pathforms.py
File metadata and controls
80 lines (77 loc) · 2.58 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
from django import forms
from .models import Property, Unit
from django.utils import timezone
class PropertyForm(forms.ModelForm):
"""Form for adding/editing property details"""
class Meta:
model = Property
fields = [
'name', 'address', 'location', 'description',
'rooms', 'rent', 'status', 'utilities'
]
widgets = {
'name': forms.TextInput(attrs={
'class': 'form-control',
'placeholder': 'e.g., Sunset Villas, Downtown Apartments'
}),
'address': forms.Textarea(attrs={
'class': 'form-control',
'rows': 2,
'placeholder': 'Full physical address of the property'
}),
'location': forms.TextInput(attrs={
'class': 'form-control',
'placeholder': 'e.g., Kileleshwa, Westlands'
}),
'description': forms.Textarea(attrs={
'class': 'form-control',
'rows': 3,
'placeholder': 'Detailed description of the property and its features'
}),
'rooms': forms.NumberInput(attrs={
'class': 'form-control',
'min': 1
}),
'rent': forms.NumberInput(attrs={
'class': 'form-control',
'min': 0,
'step': '0.01'
}),
'status': forms.Select(attrs={'class': 'form-select'}),
'utilities': forms.TextInput(attrs={
'class': 'form-control',
'placeholder': 'e.g., Water, Electricity, Internet'
}),
}
help_texts = {
'utilities': 'Separate multiple utilities with commas',
}
class UnitForm(forms.ModelForm):
"""Form for adding/editing units within a property"""
class Meta:
model = Unit
fields = ['unit_number', 'rent_amount', 'is_occupied']
widgets = {
'unit_number': forms.TextInput(attrs={
'class': 'form-control',
'placeholder': 'e.g., A1, B2, Room 5'
}),
'rent_amount': forms.NumberInput(attrs={
'class': 'form-control',
'min': 0,
'step': '0.01'
}),
'is_occupied': forms.CheckboxInput(attrs={
'class': 'form-check-input',
'role': 'switch'
})
}
UnitFormSet = forms.inlineformset_factory(
Property,
Unit,
form=UnitForm,
extra=1,
can_delete=True,
min_num=1,
validate_min=True
)