-2

serializer.py:

from .models import stock
from rest_framework import serializers


class StockSerializer(serializers.ModelSerializer):
    class Meta:
        model = stock
        fields = ('id', 'stock_name', 'price', 'stock_gain', 'market_name')

views.py:

from django.shortcuts import render
from rest_framework import viewsets, filters
from .seriaizer import StockSerializer
from .models import stock
from django_filters.rest_framework import DjangoFilterBackend


class StockViews(viewsets.ModelViewSet):
    queryset = stock.objects.all()
    serializer_class = StockSerializer
    filter_backends = (DjangoFilterBackend, filters.OrderingFilter)
    search_fields = ('stock_name',)
    ordering = ('stock_gain',)

urls.py:

from django.contrib import admin
from django.conf.urls import url
from django.urls import path, include
from rest_framework import routers
from restapp.views import StockViews
from restapp import views


router = routers.DefaultRouter()
router.register('stock', views.StockViews)

urlpatterns = [
    url(r'', include(router.urls)),
    path('admin/', admin.site.urls),
]

this error comes to me: ImportError: cannot import name 'six' from 'django.utils' (C:\Users\hajar\OneDrive\Desktop\stockm\env\lib\site-packages\django\utils_init_.py)

i installes six pip install six

but not work???? may any one can help my?!

H Abdullah
  • 53
  • 6

1 Answers1

0

this error may be due to the older versions of the dependencies that you use in your project like djangorestframework or django-cors-headers. Please upgrade those to the latest version. The following may help

pip install --upgrade django-cors-headers
pip install --upgrade djangorestframework