Changes in the event model to take the event source
This commit is contained in:
@@ -34,6 +34,10 @@ class EventForm(forms.ModelForm):
|
|||||||
|
|
||||||
def __init__(self, *args, **kwargs):
|
def __init__(self, *args, **kwargs):
|
||||||
super().__init__(*args, **kwargs)
|
super().__init__(*args, **kwargs)
|
||||||
|
# Set source to 'official' only and hide the field
|
||||||
|
self.fields['source'].initial = 'official'
|
||||||
|
self.fields['source'].widget = forms.HiddenInput()
|
||||||
|
|
||||||
# Check if all_year_event is True (from instance or initial data)
|
# Check if all_year_event is True (from instance or initial data)
|
||||||
all_year_event = False
|
all_year_event = False
|
||||||
if self.instance and self.instance.pk:
|
if self.instance and self.instance.pk:
|
||||||
@@ -54,6 +58,9 @@ class EventForm(forms.ModelForm):
|
|||||||
cleaned_data = super().clean()
|
cleaned_data = super().clean()
|
||||||
all_year_event = cleaned_data.get('all_year_event', False)
|
all_year_event = cleaned_data.get('all_year_event', False)
|
||||||
|
|
||||||
|
# Force source to be 'official' only
|
||||||
|
cleaned_data['source'] = 'official'
|
||||||
|
|
||||||
# If all_year_event is True, clear date/time fields
|
# If all_year_event is True, clear date/time fields
|
||||||
if all_year_event:
|
if all_year_event:
|
||||||
cleaned_data['start_date'] = None
|
cleaned_data['start_date'] = None
|
||||||
|
|||||||
18
events/migrations/0005_event_source.py
Normal file
18
events/migrations/0005_event_source.py
Normal file
@@ -0,0 +1,18 @@
|
|||||||
|
# Generated by Django 5.0 on 2025-12-19 22:31
|
||||||
|
|
||||||
|
from django.db import migrations, models
|
||||||
|
|
||||||
|
|
||||||
|
class Migration(migrations.Migration):
|
||||||
|
|
||||||
|
dependencies = [
|
||||||
|
('events', '0004_event_all_year_event_alter_event_end_date_and_more'),
|
||||||
|
]
|
||||||
|
|
||||||
|
operations = [
|
||||||
|
migrations.AddField(
|
||||||
|
model_name='event',
|
||||||
|
name='source',
|
||||||
|
field=models.CharField(blank=True, choices=[('eventify', 'Eventify'), ('community', 'Community')], max_length=250),
|
||||||
|
),
|
||||||
|
]
|
||||||
18
events/migrations/0006_alter_event_source.py
Normal file
18
events/migrations/0006_alter_event_source.py
Normal file
@@ -0,0 +1,18 @@
|
|||||||
|
# Generated by Django 5.0 on 2025-12-19 22:33
|
||||||
|
|
||||||
|
from django.db import migrations, models
|
||||||
|
|
||||||
|
|
||||||
|
class Migration(migrations.Migration):
|
||||||
|
|
||||||
|
dependencies = [
|
||||||
|
('events', '0005_event_source'),
|
||||||
|
]
|
||||||
|
|
||||||
|
operations = [
|
||||||
|
migrations.AlterField(
|
||||||
|
model_name='event',
|
||||||
|
name='source',
|
||||||
|
field=models.CharField(blank=True, choices=[('official', 'Official'), ('community', 'Community')], max_length=250),
|
||||||
|
),
|
||||||
|
]
|
||||||
@@ -1,3 +1,4 @@
|
|||||||
|
from random import choices
|
||||||
from django.db import models
|
from django.db import models
|
||||||
from master_data.models import EventType
|
from master_data.models import EventType
|
||||||
|
|
||||||
@@ -38,6 +39,11 @@ class Event(models.Model):
|
|||||||
important_information = models.TextField(blank=True)
|
important_information = models.TextField(blank=True)
|
||||||
venue_name = models.CharField(max_length=250, blank=True)
|
venue_name = models.CharField(max_length=250, blank=True)
|
||||||
|
|
||||||
|
source = models.CharField(max_length=250, blank=True, choices=[
|
||||||
|
('official', 'Official'),
|
||||||
|
('community', 'Community'),
|
||||||
|
])
|
||||||
|
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
return f"{self.name} ({self.start_date})"
|
return f"{self.name} ({self.start_date})"
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user