Files
goodtimes/manage_events/forms.py
2024-02-29 22:00:21 +05:30

75 lines
2.9 KiB
Python

from django import forms
from manage_events.models import EventMaster, Event, EventCategory
class EventCategoryForm(forms.ModelForm):
# image = forms.ImageField()
class Meta:
model = EventCategory
fields = ["title", "image", "description", "video_url"]
widgets = {
"image": forms.FileInput(attrs={"class": "form-control-file"}),
}
class EventForm(forms.ModelForm):
class Meta:
model = Event
fields = [
"title",
"event_master",
"description",
"image",
"status",
"start_date",
"end_date",
"from_time",
"to_time",
"category",
"venue",
"venue_capacity",
"video_url",
"entry_type",
"entry_fee",
"key_guest",
"age_group",
"draft",
]
widgets = {
"title": forms.TextInput(attrs={"class": "form-control"}),
"description": forms.Textarea(attrs={"class": "form-control", "rows": 4}),
"status": forms.Select(attrs={"class": "form-control"}),
"start_date": forms.DateInput(
attrs={"class": "form-control", "type": "date"}
),
"end_date": forms.DateInput(
attrs={"class": "form-control", "type": "date"}
),
"from_time": forms.TimeInput(
attrs={"class": "form-control", "type": "time"}
),
"to_time": forms.TimeInput(attrs={"class": "form-control", "type": "time"}),
"venue_capacity": forms.NumberInput(attrs={"class": "form-control"}),
"video_url": forms.URLInput(attrs={"class": "form-control"}),
"entry_type": forms.TextInput(attrs={"class": "form-control"}),
"entry_fee": forms.NumberInput(attrs={"class": "form-control"}),
"key_guest": forms.Textarea(attrs={"class": "form-control", "rows": 3}),
"age_group": forms.TextInput(attrs={"class": "form-control"}),
"draft": forms.CheckboxInput(attrs={"class": "form-check-input"}),
# For the 'image' field, you might not need to specify a widget since the default is appropriate.
# However, if you want to add specific classes or attributes, you can do it like this:
"image": forms.FileInput(attrs={"class": "form-control-file"}),
# For ForeignKey fields like 'EventMaster' and 'venue', Django uses a select widget by default.
# You can customize it further if needed:
"event_master": forms.Select(attrs={"class": "form-control"}),
"venue": forms.Select(attrs={"class": "form-control"}),
"category": forms.Select(attrs={"class": "form-control"}),
}
class EventMasterForm(forms.ModelForm):
class Meta:
model = EventMaster
fields = "__all__" # Includes all fields from the model