Updates for the eventify model to enable teh all year event
This commit is contained in:
18
accounts/migrations/0007_alter_user_profile_picture.py
Normal file
18
accounts/migrations/0007_alter_user_profile_picture.py
Normal file
@@ -0,0 +1,18 @@
|
||||
# Generated by Django 5.0 on 2025-12-19 22:14
|
||||
|
||||
from django.db import migrations, models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('accounts', '0006_user_profile_picture'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AlterField(
|
||||
model_name='user',
|
||||
name='profile_picture',
|
||||
field=models.ImageField(blank=True, default='default.png', null=True, upload_to='profile_pictures/'),
|
||||
),
|
||||
]
|
||||
@@ -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
|
||||
|
||||
@@ -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),
|
||||
),
|
||||
]
|
||||
@@ -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)
|
||||
|
||||
@@ -20,4 +20,30 @@
|
||||
<a class="btn btn-secondary" href="{% url 'events:event_list' %}">Cancel</a>
|
||||
</form>
|
||||
</div>
|
||||
|
||||
<script>
|
||||
document.addEventListener('DOMContentLoaded', function() {
|
||||
const allYearEventCheckbox = document.getElementById('id_all_year_event');
|
||||
const startDateField = document.getElementById('id_start_date');
|
||||
const endDateField = document.getElementById('id_end_date');
|
||||
const startTimeField = document.getElementById('id_start_time');
|
||||
const endTimeField = document.getElementById('id_end_time');
|
||||
|
||||
function toggleDateTimeFields() {
|
||||
const isDisabled = allYearEventCheckbox.checked;
|
||||
startDateField.disabled = isDisabled;
|
||||
endDateField.disabled = isDisabled;
|
||||
startTimeField.disabled = isDisabled;
|
||||
endTimeField.disabled = isDisabled;
|
||||
}
|
||||
|
||||
// Set initial state
|
||||
toggleDateTimeFields();
|
||||
|
||||
// Listen for checkbox changes
|
||||
if (allYearEventCheckbox) {
|
||||
allYearEventCheckbox.addEventListener('change', toggleDateTimeFields);
|
||||
}
|
||||
});
|
||||
</script>
|
||||
{% endblock %}
|
||||
|
||||
Reference in New Issue
Block a user