Files
demo-alarms/alerts/forms.py
Andros Fenollosa 23ac15664e Initial commit: Django LiveView alert system
Real-time alert system using Django LiveView with WebSocket support.
Features include:
- Real-time alert creation, viewing, and deletion
- Broadcast notifications to all connected users
- SQLite database
- Stimulus.js integration for interactive UI
- Modal dialogs for alert details
- Alert form with validation

Fixed Stimulus controller scope issue by placing data-controller on html element.
2025-12-08 12:27:58 +01:00

21 lines
712 B
Python

from django import forms
from .models import Alert
class AlertForm(forms.ModelForm):
class Meta:
model = Alert
fields = ['type', 'description']
widgets = {
'type': forms.Select(attrs={'class': 'input'}),
'description': forms.Textarea(attrs={'class': 'textarea', 'rows': 4}),
}
def clean_description(self):
description = self.cleaned_data.get('description')
if not description or len(description.strip()) == 0:
raise forms.ValidationError('Description is required.')
if len(description) > 500:
raise forms.ValidationError('Description must be less than 500 characters.')
return description