Updates for the eventify model to enable teh all year event

This commit is contained in:
Vivek
2025-12-20 03:46:04 +05:30
parent d1e618e06b
commit 1f9269467c
5 changed files with 111 additions and 6 deletions

View File

@@ -13,10 +13,11 @@ class EventForm(forms.ModelForm):
'title': forms.TextInput(attrs={'class': 'form-control'}),
'important_information': forms.Textarea(attrs={'class': 'form-control'}),
'venue_name': forms.TextInput(attrs={'class': 'form-control'}),
'start_date': forms.DateInput(attrs={'class': 'form-control', 'type': 'date'}),
'end_date': forms.DateInput(attrs={'class': 'form-control', 'type': 'date'}),
'start_time': forms.TimeInput(attrs={'class': 'form-control', 'type': 'time'}),
'end_time': forms.TimeInput(attrs={'class': 'form-control', 'type': 'time'}),
'start_date': forms.DateInput(attrs={'class': 'form-control', 'type': 'date', 'id': 'id_start_date'}),
'end_date': forms.DateInput(attrs={'class': 'form-control', 'type': 'date', 'id': 'id_end_date'}),
'start_time': forms.TimeInput(attrs={'class': 'form-control', 'type': 'time', 'id': 'id_start_time'}),
'end_time': forms.TimeInput(attrs={'class': 'form-control', 'type': 'time', 'id': 'id_end_time'}),
'all_year_event': forms.CheckboxInput(attrs={'class': 'form-check-input', 'id': 'id_all_year_event'}),
'latitude': forms.NumberInput(attrs={'class': 'form-control'}),
'longitude': forms.NumberInput(attrs={'class': 'form-control'}),
'pincode': forms.TextInput(attrs={'class': 'form-control'}),
@@ -31,6 +32,37 @@ class EventForm(forms.ModelForm):
'is_eventify_event': forms.CheckboxInput(attrs={'class': 'form-check-input'}),
}
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
# Check if all_year_event is True (from instance or initial data)
all_year_event = False
if self.instance and self.instance.pk:
all_year_event = self.instance.all_year_event
elif 'all_year_event' in self.initial:
all_year_event = self.initial['all_year_event']
elif self.data and 'all_year_event' in self.data:
all_year_event = self.data.get('all_year_event') == 'on' or self.data.get('all_year_event') == 'True'
# If all_year_event is True, disable date/time fields
if all_year_event:
self.fields['start_date'].widget.attrs['disabled'] = True
self.fields['end_date'].widget.attrs['disabled'] = True
self.fields['start_time'].widget.attrs['disabled'] = True
self.fields['end_time'].widget.attrs['disabled'] = True
def clean(self):
cleaned_data = super().clean()
all_year_event = cleaned_data.get('all_year_event', False)
# If all_year_event is True, clear date/time fields
if all_year_event:
cleaned_data['start_date'] = None
cleaned_data['end_date'] = None
cleaned_data['start_time'] = None
cleaned_data['end_time'] = None
return cleaned_data
class MultipleFileInput(forms.ClearableFileInput):
allow_multiple_selected = True

View File

@@ -0,0 +1,28 @@
# Generated by Django 5.0 on 2025-12-19 22:14
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('events', '0003_event_end_time_event_start_time'),
]
operations = [
migrations.AddField(
model_name='event',
name='all_year_event',
field=models.BooleanField(default=False),
),
migrations.AlterField(
model_name='event',
name='end_date',
field=models.DateField(blank=True, null=True),
),
migrations.AlterField(
model_name='event',
name='start_date',
field=models.DateField(blank=True, null=True),
),
]

View File

@@ -6,10 +6,11 @@ class Event(models.Model):
created_date = models.DateField(auto_now_add=True)
name = models.CharField(max_length=200)
description = models.TextField()
start_date = models.DateField()
end_date = models.DateField()
start_date = models.DateField(blank=True, null=True)
end_date = models.DateField(blank=True, null=True)
start_time = models.TimeField(blank=True, null=True)
end_time = models.TimeField(blank=True, null=True)
all_year_event = models.BooleanField(default=False)
latitude = models.DecimalField(max_digits=9, decimal_places=6)
longitude = models.DecimalField(max_digits=9, decimal_places=6)