modelviewset 1

modelviewset

class AccountViewSet(viewsets.ModelViewSet):
    """
    A simple ViewSet for viewing and editing accounts.
    """
    queryset = Account.objects.all()
    serializer_class = AccountSerializer
    permission_classes = [IsAccountAdminOrReadOnly]

Here is what the above code is Doing:
1. We’re importing the viewsets module from rest_framework.
2. We’re importing the Account model from the accounts app.
3. We’re importing the AccountSerializer from the accounts app.
4. We’re importing the IsAccountAdminOrReadOnly permission from the accounts app.
5. We’re defining a viewset called AccountViewSet.
6. We’re telling the viewset to use the Account model.
7. We’re telling the viewset to use the AccountSerializer.
8. We’re telling the viewset to use the IsAccountAdminOrReadOnly permission.

Similar Posts