You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

20 lines
561 B

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)