Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

AttributeError: type object has no attribute 'get_extra_actions'

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

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

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))
]

>Solution :

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))
]
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading