totaltotals
totaltotals

Reputation: 793

'Options' object has no attribute 'get_all_related_objects' but I'm already using Django 1.11

I keep getting an 'Options' object has no attribute 'get_all_related_objects' error. I've researched and people say it is often an issue with using an old version of django, but I'm using 1.11.6

when I navigate to the url: app/employees I get this error.

What am I doing wrong?

Django Version:     1.11.6
Exception Type:     AttributeError
Exception Value:    

'Options' object has no attribute 'get_all_related_objects'

other version numbers:

app/model:

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)

app/serializer:

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

app/api.py:

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

app/url.py

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

Upvotes: 0

Views: 2594

Answers (1)

anupsabraham
anupsabraham

Reputation: 3069

Django v1.11 support is not added for django-rest-framework until version 3.7. Upgrading django-rest-framework should fix the issue.

To upgrade django-rest-framework, pip install -U djangorestframework

Upvotes: 3

Related Questions