Created
February 25, 2017 13:01
-
-
Save hseritt/248f5bfec65cfad3eefb9e8963f5763c to your computer and use it in GitHub Desktop.
Django forms - adding request object into form for evaluation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class ProjectUpdateForm(ModelForm): | |
""" | |
Form for updating projects. | |
""" | |
members = forms.ModelMultipleChoiceField( | |
queryset=User.objects.all().order_by('username'), required=False) | |
lead_user = forms.ModelChoiceField( | |
queryset=User.objects.all().order_by('username'), required=False) | |
def __init__(self, *args, **kwargs): | |
request = kwargs.pop("request") | |
super(ProjectUpdateForm, self).__init__(*args, **kwargs) | |
if not request.user.is_superuser and \ | |
request.user.contact.organization.org_type != 'Owner': | |
self.fields['organization'] = forms.ModelChoiceField( | |
queryset=Organization.objects.filter( | |
id=request.user.contact.organization.id | |
) | |
) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment