<s> from rest_framework . generics import get_object_or_404 <EOL> from django . contrib . auth import get_user_model <EOL> from django . contrib . auth . models import Group <EOL> class UserRelatedMixin ( object ) : <EOL> def get_user ( self ) : <EOL> queryset = get_user_model ( ) . objects . all ( ) <EOL> obj = get_object_or_404 ( queryset , username = self . kwargs . get ( '<STR_LIT:username>' ) ) <EOL> self . check_object_permissions ( self . request , obj ) <EOL> return obj <EOL> def get_permissioned_object ( self ) : <EOL> return self . get_user ( ) <EOL> class GroupRelatedMixin ( object ) : <EOL> def get_group ( self ) : <EOL> queryset = Group . objects . all ( ) <EOL> obj = get_object_or_404 ( queryset , name = self . kwargs . get ( '<STR_LIT:name>' ) ) <EOL> self . check_object_permissions ( self . request , obj ) <EOL> return obj <EOL> def get_permissioned_object ( self ) : <EOL> return self . get_group ( ) </s>
