def get_extra_kwargs(self): """ Filter out the 'company' field when the user is from management. :return: A sequence with the extra field kwargs. :rtype: tuple """ kwargs = ModelSerializer.get_extra_kwargs(self) if not is_management(self.context["request"].user): return kwargs return { **kwargs, "company": { **kwargs.get("company", {}), "read_only": True } }
def get_extra_kwargs(self): """ Overridden to hide the answerer for management or employer. This is because a employee may never know who gave answers except when the user created a reflection, but that's handled within the ReflectionSerializer. :return: The extra keyword arguments for the fields :rtype: dict """ extra = ModelSerializer.get_extra_kwargs(self) if is_employee(self.context.request.user): current_arguments = extra.get(extra["answerer"], {}) extra["answerer"] = {**current_arguments, "write_only": False} return extra