PonyConf/cfp/forms.py

22 lines
611 B
Python
Raw Normal View History

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