AttributeError: type object 'ContactsViewSet' has no attribute 'get_extra_actions'
Guys, I am not able to raise the server due to this error after I have inserted the necessary classes for the use of Bulk.
Unhandled exception in thread started by <function check_errors.<locals>.wrapper at 0x7f8493c1d620>
Traceback (most recent call last):
File "/var/www/django/WebWhatsAppExploitServer/venv/lib64/python3.6/site-packages/django/utils/autoreload.py", line 225, in wrapper
fn(*args, **kwargs)
File "/var/www/django/WebWhatsAppExploitServer/venv/lib64/python3.6/site-packages/django/core/management/commands/runserver.py", line 117, in inner_run
self.check(display_num_errors=True)
File "/var/www/django/WebWhatsAppExploitServer/venv/lib64/python3.6/site-packages/django/core/management/base.py", line 379, in check
include_deployment_checks=include_deployment_checks,
File "/var/www/django/WebWhatsAppExploitServer/venv/lib64/python3.6/site-packages/django/core/management/base.py", line 366, in _run_checks
return checks.run_checks(**kwargs)
File "/var/www/django/WebWhatsAppExploitServer/venv/lib64/python3.6/site-packages/django/core/checks/registry.py", line 71, in run_checks
new_errors = check(app_configs=app_configs)
File "/var/www/django/WebWhatsAppExploitServer/venv/lib64/python3.6/site-packages/django/core/checks/urls.py", line 13, in check_url_config
return check_resolver(resolver)
File "/var/www/django/WebWhatsAppExploitServer/venv/lib64/python3.6/site-packages/django/core/checks/urls.py", line 23, in check_resolver
return check_method()
File "/var/www/django/WebWhatsAppExploitServer/venv/lib64/python3.6/site-packages/django/urls/resolvers.py", line 396, in check
for pattern in self.url_patterns:
File "/var/www/django/WebWhatsAppExploitServer/venv/lib64/python3.6/site-packages/django/utils/functional.py", line 37, in __get__
res = instance.__dict__[self.name] = self.func(instance)
File "/var/www/django/WebWhatsAppExploitServer/venv/lib64/python3.6/site-packages/django/urls/resolvers.py", line 533, in url_patterns
patterns = getattr(self.urlconf_module, "urlpatterns", self.urlconf_module)
File "/var/www/django/WebWhatsAppExploitServer/venv/lib64/python3.6/site-packages/django/utils/functional.py", line 37, in __get__
res = instance.__dict__[self.name] = self.func(instance)
File "/var/www/django/WebWhatsAppExploitServer/venv/lib64/python3.6/site-packages/django/urls/resolvers.py", line 526, in urlconf_module
return import_module(self.urlconf_name)
File "/opt/rh/rh-python36/root/usr/lib64/python3.6/importlib/__init__.py", line 126, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "<frozen importlib._bootstrap>", line 994, in _gcd_import
File "<frozen importlib._bootstrap>", line 971, in _find_and_load
File "<frozen importlib._bootstrap>", line 955, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 665, in _load_unlocked
File "<frozen importlib._bootstrap_external>", line 678, in exec_module
File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
File "/var/www/django/WebWhatsAppExploitServer/APICAMPAIGN/urls.py", line 19, in <module>
path('api/', include('bots_api.urls')),
File "/var/www/django/WebWhatsAppExploitServer/venv/lib64/python3.6/site-packages/django/urls/conf.py", line 34, in include
urlconf_module = import_module(urlconf_module)
File "/opt/rh/rh-python36/root/usr/lib64/python3.6/importlib/__init__.py", line 126, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "<frozen importlib._bootstrap>", line 994, in _gcd_import
File "<frozen importlib._bootstrap>", line 971, in _find_and_load
File "<frozen importlib._bootstrap>", line 955, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 665, in _load_unlocked
File "<frozen importlib._bootstrap_external>", line 678, in exec_module
File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
File "/var/www/django/WebWhatsAppExploitServer/bots_api/urls.py", line 48, in <module>
path('',bulk_router.get_urls()),
File "/var/www/django/WebWhatsAppExploitServer/venv/lib64/python3.6/site-packages/rest_framework/routers.py", line 363, in get_urls
urls = super(DefaultRouter, self).get_urls()
File "/var/www/django/WebWhatsAppExploitServer/venv/lib64/python3.6/site-packages/rest_framework/routers.py", line 261, in get_urls
routes = self.get_routes(viewset)
File "/var/www/django/WebWhatsAppExploitServer/venv/lib64/python3.6/site-packages/rest_framework/routers.py", line 176, in get_routes
extra_actions = viewset.get_extra_actions()
AttributeError: type object 'ContactsViewSet' has no attribute 'get_extra_actions'
Here's a snippet of what I'm doing.
(app)/urls.py
urlpatterns = [
path('api/', include('bots_api.urls')),
]
bots_api/urls.py
bulk_routes = [
('contacts/list', ContactsViewSet, 'Contacts List'),
('contacts/details', ContactsDetailsViewSet, 'Contacts List'),
('contacts/blacklist', ContactBlackListViewSet, 'Contacts Black List')
]
bulk_router = BulkRouter()
for route in bulk_routes:
bulk_router.register(route[0],route[1],route[2])
urlpatterns = [
path('',include(bulk_router.urls)),
]
serializers/contacts.py
class ContactsSerializer(BulkSerializerMixin, serializers.ModelSerializer):
class Meta(object):
from bots_api.models import Contacts
model = Contacts
fields = ('__all__')
list_serializer_class = BulkListSerializer
views/contacts.py
class ContactsViewSet(ListBulkCreateUpdateDestroyAPIView):
from bots_api.lib.serializers.contacts import ContactsSerializer
serializer_class = ContactsSerializer
filter_backends = (filters.OrderingFilter,
filters.SearchFilter,
DjangoFilterBackend)
search_fields = ['phone_number', 'phone_region', 'phone_type', 'tag', 'created',
'updated']
def get_queryset(self):
contact_id = self.request.query_params.get('id', None)
client_id = self.request.query_params.get('client', None)
number = self.request.query_params.get('number', None)
active = self.request.query_params.get('active', None)
queryset = self.ContactsSerializer.Meta.Contacts.objects.all()
if contact_id:
queryset = queryset.filter(id=contact_id)
if client_id:
queryset = queryset.filter(client_id=client_id)
if number:
queryset = queryset.filter(phone_number__contains=number)
if not active is None:
queryset = queryset.filter(active=active)
return queryset
I've been having this problem since yesterday, does anyone know where I might be going wrong?
same here
@tolsac @riquedev get_extra_action is only in rest_framework >= 3.8 and work with decorator @action.
Install an earlier version may temporarily fix this issue.
@tolsac @riquedev
Sorry I was wrong.
I guess riquedev's issue is because he treated an APIView obj as a ViewSet.
class ContactsViewSet(ListBulkCreateUpdateDestroyAPIView):
The ways that they are added to routers are quite different. Check https://www.django-rest-framework.org/api-guide/routers/#using-include-with-routers
Try .as_view() instead.
Just to clarify what @Karmenzind said changing:
class ContactsViewSet(ListBulkCreateUpdateDestroyAPIView):
to:
class ContactsViewSet(BulkModelViewSet):
Should fix that issue.
I ran into the same issue and fixed it for me.
Also, it would be nice if there was more information on setting up ViewSets
@Luid101 Thanks for the info. This worked for me