Django Rest Framework – AssertionError Fix your URL conf, or set the `.lookup_field` attribute on the view correctly

I’m trying to return as single object (not a queryset) that is specific to a user without them having to specify an identifier/pk within the requested URL. Each user has an organisation FK. i.e. http://website/organisation and not http://website/organisation/1 I’m receiving the following error, since it’s expecting this identifier: AssertionError: Expected view OrganisationDetail to be called … Read more

Using the reserved word “class” as field name in Django and Django REST Framework

Description of the problem Taxonomy is the science of defining and naming groups of biological organisms on the basis of shared characteristics. Organisms are grouped together into taxa (singular: taxon) and these groups are given a taxonomic rank. The principal ranks in modern use are domain, kingdom, phylum, class, order, family, genus and species. More … Read more

Duplicate elements in Django Paginate after `order_by` call

I’m using Django 1.7.7. I’m wondering if anyone has experienced this. This is my query: events = Event.objects.filter( Q(date__gt=my_date) | Q(date__isnull=True) ).filter(type__in=[…]).order_by(‘date’) When I try to then paginate it p = Paginator(events, 10) p.count # Gives 91 event_ids = [] for i in xrange(1, p.count / 10 + 2): event_ids += [i.id for i in … Read more

How can I use OrderingFilter without exposing the names of the fields in the database

I have a model that uses the OrderingFilter Backend. Right now only ordering by field id is allowed. I want to give the option for ordering by other fields too but without having to expose the field names in my database. Is there a way to do that? Answer pip install django-filter In your view: … Read more

Django Rest Framework custom response message

I have two questions about Django Rest Framework response message 1. When use generics.ListCreateAPIView or RetrieveDestroyAPIView , usually return a resource For example ,call /map/ with POST Method The result will like a object : { “x_axis”: “23”, “y_axis”: “25”, “map_id”: 1, } I want to know can I edit this message to custom like … Read more

‘ListSerializer’ object is not callable

I am trying to implement Django-Rest framework for a voting application with content_type objects. I tried using the rest-framework-generic-relations for serializers.py. It seems to me that the error might be within serializer.py / views.py, but I am new to this framework and would appreciate your help! views.py: class vote_detail(generics.RetrieveUpdateDestroyAPIView): queryset = VotedItem.objects.all() serializer_class = VoteSerializer(queryset, … Read more

Displaying Django subcategories in category and products in each category json as Json Child

Hi in my Django oscar project which Implements Django oscar. I am able to implement my custom API which I use to view categories and display them. The issue with the API now is that subcategories of a category appear in my API view as categories and I would like them to be in an … Read more

how to create serializer for an enum field in django rest framework

i am writing an API in python django rest framework and i am stuck at creating a serializer field for an ENUM, how can i create a serializer field for an ENUM field. my model code is: class Queue(models.Model): class Meta: db_table = ‘queues’ id = models.UUIDField(primary_key=True, default=uuid.uuid4, editable=False, unique=True) name = models.CharField(max_length=45) type = … Read more

How to apply a filter backend to all fields of all resources in Django Rest Framework?

I have a lot of resources and i want to apply the DjangoFilterBackend to all of them. Tried setting in settings.py ‘DEFAULT_FILTER_BACKENDS’: [ ‘rest_framework.filters.DjangoFilterBackend’, ] But it didn’t work I tried adding only filter_backends = (filters.DjangoFilterBackend,) to one of my resources and it still didn’t work. Only after I explicitly added filter_fields = (‘col1′,’col2’,) it … Read more

‘CityListViewSet’ should either include a `serializer_class` attribute, or override the `get_serializer_class()` method

I am assuming by the error in the title, once more here for clarity ‘CityListViewSet’ should either include a `serializer_class` attribute, or override the `get_serializer_class()` method. that my serializer isn’t connected to my view, which in my code it should be. I’m not really sure where the bug is in this one. I wonder if … Read more