-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathforms.py
54 lines (39 loc) · 1.51 KB
/
forms.py
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
from django.forms import ModelForm
from auctions.models import AuctionItem, AuctionBid, Comment
# Create forms
class AuctionForm(ModelForm):
class Meta:
model = AuctionItem
fields = "__all__"
exclude = ["listed_by", "closed"]
labels = {
"name": "Item Name",
"image": "Upload a clear image of your item",
"image_url": "Image link",
"category": "Select Item Category",
"description": "Item Description",
"price": "Current price",
"starting_bid": "Bidding price",
}
# adding styles to the form by adding the css class to be modified
def __init__(self, *args, **kwargs):
super(AuctionForm, self).__init__(*args, **kwargs)
for name, field in self.fields.items():
field.widget.attrs.update({'class': 'form-control form-label'})
class AuctionBidForm(ModelForm):
class Meta:
model = AuctionBid
fields = ["bid"]
labels = {
"bid": "Bid Amount:",
}
def __init__(self, *args, **kwargs):
super(AuctionBidForm, self).__init__(*args, **kwargs)
self.fields['bid'].widget.attrs.update({'class': 'form-control'})
class CommentForm(ModelForm):
class Meta:
model = Comment
fields = ["body"]
def __init__(self, *args, **kwargs):
super(CommentForm, self).__init__(*args, **kwargs)
self.fields['body'].widget.attrs.update({'class': 'form-control', 'placeholder': 'Enter your comment'})