2017-05-30 20:27:45 +00:00
|
|
|
from django import forms
|
|
|
|
from django.forms.models import modelform_factory
|
|
|
|
|
2017-07-30 16:47:10 +00:00
|
|
|
from .models import Participant, Talk
|
2017-05-30 20:27:45 +00:00
|
|
|
|
|
|
|
|
2017-07-30 16:07:09 +00:00
|
|
|
class TalkForm(forms.ModelForm):
|
|
|
|
def __init__(self, *args, **kwargs):
|
2017-07-30 16:47:10 +00:00
|
|
|
categories = kwargs.pop('categories')
|
2017-07-30 16:07:09 +00:00
|
|
|
super().__init__(*args, **kwargs)
|
2017-07-30 16:47:10 +00:00
|
|
|
if categories.exists():
|
|
|
|
self.fields['category'].queryset = categories
|
2017-07-30 16:07:09 +00:00
|
|
|
else:
|
2017-07-30 16:47:10 +00:00
|
|
|
del self.fields['category']
|
2017-05-30 20:27:45 +00:00
|
|
|
|
2017-07-30 16:07:09 +00:00
|
|
|
class Meta:
|
|
|
|
model = Talk
|
|
|
|
fields = ('category', 'title', 'description','notes')
|
2017-05-30 20:27:45 +00:00
|
|
|
|
2017-07-30 16:07:09 +00:00
|
|
|
|
|
|
|
ParticipantForm = modelform_factory(Participant, fields=('name','email', 'biography'))
|