2022-12-23 11:01:29 +00:00
|
|
|
from assets.models import Host, Asset
|
2023-02-01 09:03:42 +00:00
|
|
|
from assets.serializers import HostSerializer, HostInfoSerializer
|
|
|
|
from rest_framework.decorators import action
|
|
|
|
from rest_framework.response import Response
|
|
|
|
|
2022-08-22 10:32:33 +00:00
|
|
|
from .asset import AssetViewSet
|
2022-04-06 03:29:16 +00:00
|
|
|
|
|
|
|
__all__ = ['HostViewSet']
|
|
|
|
|
|
|
|
|
|
|
|
class HostViewSet(AssetViewSet):
|
|
|
|
model = Host
|
2022-12-23 11:01:29 +00:00
|
|
|
perm_model = Asset
|
2022-04-06 03:29:16 +00:00
|
|
|
|
|
|
|
def get_serializer_classes(self):
|
|
|
|
serializer_classes = super().get_serializer_classes()
|
|
|
|
serializer_classes['default'] = HostSerializer
|
2023-02-01 09:03:42 +00:00
|
|
|
serializer_classes['info'] = HostInfoSerializer
|
2022-04-06 03:29:16 +00:00
|
|
|
return serializer_classes
|
2023-02-01 09:03:42 +00:00
|
|
|
|
|
|
|
@action(methods=["GET"], detail=True, url_path="info")
|
|
|
|
def info(self, *args, **kwargs):
|
|
|
|
asset = super().get_object()
|
|
|
|
return Response(asset.info)
|
|
|
|
|