Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class SimpleProjectModelChoicesField(ModelChoiceField):
- def label_from_instance(self, obj):
- return '{name}'.format(name=obj.name)
- class CourseForm(ModelForm):
- project = SimpleProjectModelChoicesField(queryset=Project.objects.filter(is_active=True))
- def __init__(self, *args, **kwargs):
- self.request = kwargs.pop("request")
- if 'project_id' in kwargs:
- self.project_id = kwargs.pop("project_id")
- if self.project_id is not None:
- kwargs['initial'] = {'project': self.project_id}
- super(CourseForm, self).__init__(*args, **kwargs)
- self.fields['type'].widget.attrs.update({'class': 'form-control'})
- self.fields['project'].widget.attrs.update({'class': 'form-control'})
Add Comment
Please, Sign In to add comment