60 lines
1.8 KiB
Python
60 lines
1.8 KiB
Python
from ckeditor_uploader.widgets import CKEditorUploadingWidget
|
|
from django import forms
|
|
|
|
from .models import Post, Event, News, FetMeeting
|
|
|
|
|
|
class MyPostForm(forms.ModelForm):
|
|
class Meta:
|
|
model = Post
|
|
fields = ['title', 'subtitle', 'tags', 'image', 'body', 'slug', 'author']
|
|
|
|
widgets = {'body': CKEditorUploadingWidget(config_name='default')}
|
|
|
|
class Media:
|
|
js = (
|
|
'js/auto_slug.js', # automatic slag completion via ajax
|
|
'js/tag_completion.js', # to get a list for tag autocompletion via ajax
|
|
)
|
|
|
|
|
|
class MyNewsForm(MyPostForm):
|
|
class Meta:
|
|
model = News
|
|
fields = ['title', 'subtitle', 'tags', 'image', 'body', 'slug', 'author']
|
|
|
|
widgets = {'body': CKEditorUploadingWidget(config_name='default')}
|
|
|
|
def __init__(self, *args, **kwargs):
|
|
super().__init__(*args, **kwargs) # to get the self.fields set
|
|
|
|
|
|
class MyEventForm(MyPostForm):
|
|
class Meta:
|
|
model = Event
|
|
fields = ['title', 'subtitle', 'tags', 'image', 'body',
|
|
'event_start', 'event_end', 'event_place', 'slug', 'author']
|
|
|
|
widgets = {'body': CKEditorUploadingWidget(config_name='default')}
|
|
|
|
def __init__(self, *args, **kwargs):
|
|
super().__init__(*args, **kwargs) # to get the self.fields set
|
|
|
|
self.fields['event_start'].required = True
|
|
self.fields['event_end'].required = True
|
|
|
|
if 'event_place' in self.fields:
|
|
self.fields['event_place'].required = True
|
|
|
|
|
|
class MyFetMeetingForm(MyEventForm):
|
|
class Meta:
|
|
model = FetMeeting
|
|
fields = ['event_start', 'event_end', 'tags']
|
|
|
|
def __init__(self, *args, **kwargs):
|
|
super().__init__(*args, **kwargs) # to get the self.fields set
|
|
|
|
self.fields['event_start'].required = True
|
|
self.fields['event_end'].required = False
|