site_tps/content/forms.py

31 lines
708 B
Python
Raw Normal View History

2018-03-09 12:18:03 +00:00
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)
2018-03-10 08:28:50 +00:00
class ContentEdit(forms.ModelForm):
class Meta:
model = Content
fields = [
'name',
'file'
]