def __init__(self, *args, **kwargs): super(VBBUComponentForm, self).__init__(*args, **kwargs) # Set the kind field to readonly self.fields['kind'].widget.attrs['readonly'] = True # Define the logic for obtaining the objects for the provider_service # dropdown of the tenant form. self.fields[ 'provider_service'].queryset = MCORDService.get_service_objects( ).all() # Set the initial kind to HELLO_WORLD_KIND for this tenant. self.fields['kind'].initial = MCORD_KIND # If there is an instance of this model then we can set the initial # form values to the existing values. if self.instance: self.fields['creator'].initial = self.instance.creator self.fields[ 'display_message'].initial = self.instance.display_message # If there is not an instance then we need to set initial values. if (not self.instance) or (not self.instance.pk): self.fields['creator'].initial = get_request().user if MCORDService.get_service_objects().exists(): self.fields[ "provider_service"].initial = MCORDService.get_service_objects( ).all()[0]
def __init__(self, *args, **kwargs): super(VBBUComponentForm, self).__init__(*args, **kwargs) # Set the kind field to readonly self.fields['kind'].widget.attrs['readonly'] = True # Define the logic for obtaining the objects for the provider_service # dropdown of the tenant form. self.fields[ 'provider_service'].queryset = MCORDService.get_service_objects().all() # Set the initial kind to HELLO_WORLD_KIND for this tenant. self.fields['kind'].initial = MCORD_KIND # If there is an instance of this model then we can set the initial # form values to the existing values. if self.instance: self.fields['creator'].initial = self.instance.creator self.fields[ 'display_message'].initial = self.instance.display_message # If there is not an instance then we need to set initial values. if (not self.instance) or (not self.instance.pk): self.fields['creator'].initial = get_request().user if MCORDService.get_service_objects().exists(): self.fields["provider_service"].initial = MCORDService.get_service_objects().all()[0]
def queryset(self, request): return MCORDService.get_service_objects_by_user(request.user)