Home > Software design >  AttributeError: type object has no attribute 'get_extra_actions'
AttributeError: type object has no attribute 'get_extra_actions'

Time:12-16

I have a small web app, and I'm trying to develop an API for it. I'm having an issue with a model I have called Platform inside of an app I have called UserPlatforms. The same error: AttributeError: type object 'UserPlatformList' has no attribute 'get_extra_actions'

models.py:

class Platform(models.Model):
    user = models.ForeignKey(settings.AUTH_USER_MODEL,
                             related_name='platform_owned',
                             on_delete=models.CASCADE,
                             default=10)

    PLATFORM_CHOICES = [platform_x, platform_y]

    platform_reference = models.CharField(max_length=10, choices=PLATFORM_CHOICES, default='platform_x')
    platform_variables = models.JSONField()

api/views.py

from .serializers import PlatformSerializer
from rest_framework import generics, permissions
from userplatforms.models import Platform

class UserPlatformList(generics.ListCreateAPIViewAPIView):
    queryset = Platform.objects.all()
    permisson_classes = [permissions.IsAuthenticatedOrReadOnly]
    serializer_class = PlatformSerializer

api/serializer.py

from rest_framework import serializers
from userplatforms.models import Platform
    
class PlatformSerializer(serializers.HyperlinkedModelSerializer):
        class Meta:
            model = Platform
            fields = '__all__'

api/urls.py

from django.urls import path, include
from . import views
from rest_framework import routers

router = routers.DefaultRouter()
router.register(r'userplatforms/', views.UserPlatformList, 'userplatforms')
router.register(r'userfiles/', views.UserFileList, "userfiles")
router.register(r'users/', views.UserList, "user")



urlpatterns = [
    path("^", include(router.urls))
]

CodePudding user response:

You cannot add generic Views in routers

So remove this line

router.register(r'userplatforms/', views.UserPlatformList, 'userplatforms')

and update urlpatterns to

urlpatterns = [
    path('userplatforms/', views.UserPlatformList, name='userplatforms'),
    path("^", include(router.urls))
]

CodePudding user response:

change class PlatformSerializer(serializers.HyperlinkedModelSerializer): to class PlatformSerializer(serializers.ModelSerializer):

  • Related