A
A
Arti-Jack2018-04-18 21:58:36
Django
Arti-Jack, 2018-04-18 21:58:36

Why is the ViewSet not being routed and registered?

I have a model class:
models.py

from __future__ import unicode_literals

from django.db import models

# Модель 
class Message(models.Model):
  msg_date = models.DateTimeField(auto_now_add=True)
  text = models.TextField()
  readed = models.BooleanField()

Serializer
It was not in the project, I created a separate file.
serializers.py
from rest_framework import serializers
from .models import Message

class MessageSerializer(serializers.ModelSerializer):
  class Meta:
    model = Message
    fields = ('id', 'title', 'body', 'created_at')

View.
view.py
from rest_framework import viewsets
from .models import Message
from .serializers import MessageSerializer

class MessageViewSet(viewsets.ModelViewSet):
  aueryset = Message.objects.all().order_by('-created_at')
  serializer_class = MessageSerializer

urls.py , which is located in the webapp directory
from django.conf.urls import url, include
from django.contrib import admin

urlpatterns = [
    url(r'^api/v1/', include('webapp.urls')),
    url(r'^admin/', admin.site.urls),
]

and urls.py which is in another folder
from rest_framework import routers
from .views import MessageViewSet

# Создаем router и регистрируем наш ViewSet
router = routers.DefaultRouter()
router.register(r'message', MessageViewSet)

# URLs настраиваются автоматически роутером
urlpatterns = router.urls

When I try to start the server, I get the following log:
router.register(r'message', MessageViewSet)
  File "/home/username/.local/lib/python3.5/site-packages/rest_framework/routers.py", line 82, in register
    base_name = self.get_default_base_name(viewset)
  File "/home/username/.local/lib/python3.5/site-packages/rest_framework/routers.py", line 161, in get_default_base_name
    assert queryset is not None, '`base_name` argument not specified, and could ' \
AssertionError: `base_name` argument not specified, and could not automatically determine the name from the viewset, as it does not have a `.queryset` attribute.

I don't understand what am I doing wrong? Why can't I do routing and register it?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
R
Rostislav Grigoriev, 2018-04-18
@Arti-Jack

There's a typo here
Not aueryset ¸ but queryset

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question