site_tps/content/forms.py
2018-03-10 09:28:50 +01:00

30 lines
708 B
Python

from django import forms
from .models import Content, Category
class CreateContent(forms.ModelForm):
class Meta:
model = Content
fields = [
'name',
'category',
'file',
]
def __init__(self, school, *args, **kwargs):
super().__init__(*args, **kwargs)
self.instance.school = school
already_created = map(lambda x:x.category.pk, school.content_set.select_related('category'))
self.fields['category'].queryset = Category.objects.exclude(pk__in=already_created)
class ContentEdit(forms.ModelForm):
class Meta:
model = Content
fields = [
'name',
'file'
]