2017-10-19 40 views
0

我不斷收到 '選項'對象沒有屬性'get_all_related_objects'錯誤。我已經研究過,並且有人說使用老版本的django時經常會遇到問題,但我使用1.11.6'選項'對象沒有屬性'get_all_related_objects',但我已經在使用Django 1.11

當我導航到url:app/employees時出現此錯誤。

我在做什麼錯?

Django Version:  1.11.6 
Exception Type:  AttributeError 
Exception Value:  

'Options' object has no attribute 'get_all_related_objects' 

其他版本號:

  • 蟒蛇:2.7.14
  • REST框架:3.1.1
  • 的virtualenv:12.1.1

應用/型號:

class Employee(models.Model): 
    first_name = models.CharField(max_length=50) 
    last_name = models.CharField(max_length=50) 
    supervisor = models.ForeignKey('self', blank=True, null=True) 
    is_active = models.BooleanField(default=True) 
    is_supervisor = models.BooleanField(default=False) 

    class Meta: 
     ordering = ('last_name',) 

    def __str__(self): 
     return "{}".format(self.first_name + ' ' + self.last_name) 

應用/串行:

class EmployeeSerializer(serializers.ModelSerializer): 
    class Meta: 
     model = Employee 

應用程序/ api.py:

class EmployeeApi(ListAPIView): 
    queryset = Employee.objects.all() 
    serializer_class = EmployeeSerializer 

應用程序/ url.py

urlpatterns = [ 
...  
url(r'^employees$', EmployeeApi.as_view()), 
] 
+0

Django的1.11支持。這可能是你的理由。嘗試升級django-rest-framework – anupsabraham

+0

@anupsabraham好的!這可能會解釋一些其他的事情正在爲我所用。我是非常新的python和django,dhw我要升級django-rest-framework嗎?使用pip? –

+0

'pip install -U djangorestframework' – anupsabraham

回答

2

Django v1.11 support is not added for django-rest-framework until version 3.7。升級django-rest-framework應該解決問題。

要升級Django的REST的架構,是不是增加了Django的休息框架,直到3.7版本我覺得pip install -U djangorestframework

+0

是的!那樣做了。我認爲這實際上是我發佈的另一個問題的答案:https://stackoverflow.com/questions/46819746/import-error-from-django-core-handlers-wsgi-import-status-code-text,可以你在那裏發佈這個答案,我會將它標記爲答案? –

相關問題