Adding DRF to existing solution, getting AttributeError: 'function' object has no attribute 'filter' #8721
Unanswered
michaeloliveraz
asked this question in
Question & Answer
Replies: 1 comment
-
Working now. Silly me, I used the Django web page instead of the api DRF page. http://localhost:8000/api/parameters/ works fine, |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
I have existing and working app with the following models.py
`#parameters/models.py
from symbol import parameters
from django.db import models
Create your models here.
from django.db import models
class Parameter(models.Model):
id = models.BigAutoField(primary_key=True)
matchingKey = models.CharField(max_length=200)
sequence = models.IntegerField(default = 1)
param_kwargs_json = models.JSONField(null=True, blank=True)
param1 = models.CharField(max_length=200)
param2 = models.CharField(max_length=200, null = True, default = 'N/A' )
param3 = models.CharField(max_length=200, null = True, default = 'N/A' )
param4 = models.CharField(max_length=200, null = True, default = 'N/A' )
param5 = models.CharField(max_length=200, null = True, default = 'N/A' )
param6 = models.CharField(max_length=200, null = True, default = 'N/A' )
param7 = models.CharField(max_length=200, null = True, default = 'N/A' )
param8 = models.CharField(max_length=200, null = True, default = 'N/A' )
param9 = models.CharField(max_length=200, null = True, default = 'N/A' )
param10 = models.CharField(max_length=200, null = True, default = 'N/A' )
description = models.CharField(max_length=250, null = True, default = 'N/A' )
`
I created an api/ app and views.py, urls.py and serializers.py
`#/api/views.py
from django.shortcuts import render
Create your views here.
from rest_framework.views import APIView
from rest_framework.response import Response
from rest_framework.decorators import api_view
from rest_framework.reverse import reverse
from rest_framework import generics
from parameters.models import Parameter
import api.serializers as serializers
class ParametersListAPIView(generics.ListCreateAPIView):
queryset = Parameter.objects.all()
serializer_class = serializers.ParametersListSerializer
class ParameterAPIView(generics.RetrieveUpdateDestroyAPIView):
queryset = Parameter.objects.all()
serializer_class = serializers.ParameterSerializer
@api_view(('GET',))
def api_root(request, format=None):
return Response({
'parameters': reverse('parameters', request=request, format=format),
})`
and
`#/api/urls.py
from django.conf.urls import url, include
from . import views
apiurls = [
urlpatterns = [
url(r'^$', views.api_root, name='api-root'),
url(r'^', include(apiurls)),
url(r'^api-auth/', include('rest_framework.urls', namespace='rest_framework'))
]
`
and finally
`#/api/serializers.py
from rest_framework import serializers
from parameters.models import Parameter
class ParametersListSerializer(serializers.ModelSerializer):
class Meta:
model = Parameter
fields = 'all'
class ParameterSerializer(serializers.ModelSerializer):
class Meta:
model = Parameter
fields = 'all'
`
When I use http://localhost:8000/parameters/ I get the /parameters/templates/paramersindex.html page.
When I click on one of the parameters items http://localhost:8000/parameters/1/
I get the following error page.
`
I am guessing I need to add a filter for parameter.id but I haven't found the place
Beta Was this translation helpful? Give feedback.
All reactions