symposion_app/symposion/schedule/forms.py

23 lines
717 B
Python
Raw Normal View History

2012-08-31 03:24:08 +00:00
from django import forms
from django.db.models import Q
2012-08-31 03:24:08 +00:00
2012-08-31 05:12:15 +00:00
from symposion.schedule.models import Presentation
2012-08-31 03:24:08 +00:00
class SlotEditForm(forms.Form):
presentation = forms.ModelChoiceField(
queryset=Presentation.objects.all(),
2012-08-31 03:24:08 +00:00
required=True,
)
def __init__(self, *args, **kwargs):
presentation = kwargs.get("initial", {}).get("presentation")
super(SlotEditForm, self).__init__(*args, **kwargs)
queryset = self.fields["presentation"].queryset
if presentation:
queryset = queryset.filter(Q(slot=None) | Q(pk=presentation.pk))
else:
queryset = queryset.filter(slot=None)
self.fields["presentation"].queryset = queryset