core: add custom group model with hierarchy , add tree admin
This commit is contained in:
		
							
								
								
									
										36
									
								
								passbook/admin/api/v1/groups.py
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										36
									
								
								passbook/admin/api/v1/groups.py
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,36 @@ | ||||
| """passbook admin gorup API""" | ||||
| from rest_framework.permissions import IsAdminUser | ||||
| from rest_framework.serializers import ModelSerializer, Serializer | ||||
| from rest_framework.viewsets import ModelViewSet | ||||
|  | ||||
| from passbook.core.models import Group | ||||
|  | ||||
|  | ||||
| class RecursiveField(Serializer): | ||||
|     """Recursive field for manytomanyfield""" | ||||
|  | ||||
|     def to_representation(self, value): | ||||
|         serializer = self.parent.parent.__class__(value, context=self.context) | ||||
|         return serializer.data | ||||
|  | ||||
|     def create(self): | ||||
|         raise NotImplementedError() | ||||
|  | ||||
|     def update(self): | ||||
|         raise NotImplementedError() | ||||
|  | ||||
| class GroupSerializer(ModelSerializer): | ||||
|     """Group Serializer""" | ||||
|  | ||||
|     children = RecursiveField(many=True) | ||||
|  | ||||
|     class Meta: | ||||
|         model = Group | ||||
|         fields = '__all__' | ||||
|  | ||||
| class GroupViewSet(ModelViewSet): | ||||
|     """Group Viewset""" | ||||
|  | ||||
|     permission_classes = [IsAdminUser] | ||||
|     serializer_class = GroupSerializer | ||||
|     queryset = Group.objects.filter(parent__isnull=True) | ||||
		Reference in New Issue
	
	Block a user
	 Jens Langhammer
					Jens Langhammer