Cannot exclude pk and model from serializer in django 1.8


I'm trying to get rid of pk and model from the output json object as part of Django serialization. I tried the below code in, but it threw the below error

TypeError: serialize() takes 2 positional arguments but 3 were given.

To solve this, I used @staticmethod as well, but no much use.

Here is the

def get_stats(request):
    if request.method == "POST":
        srch_dropV = request.POST['srch_dropAJ']
        srch_dropV = ''
    if(srch_dropV == 'Lock'):
        stud = LockBased.objects.all()
    response_data = {}
    response_data['result'] = 'Success'
    serializer = NewSerializer()
    response_data['message'] = serializer.serialize('json', stud)
    return HttpResponse(JsonResponse(response_data), content_type="application/json")

from django.core.serializers.json import Serializer, DjangoJSONEncoder
import json

class NewSerializer(Serializer):
    def end_serialization(self):
        cleaned_objects = []

        for obj in self.objects:
            del obj['pk']
            del obj['model'] 

        json.dump(cleaned_objects,, cls=DjangoJSONEncoder, **self.options)

Please help me to identify the issue and fix it.
I'm using Django 1.8 and Python 3.4.


I think you confused serializers.serialize() with serializer.serialize():

serializer = NewSerializer()
response_data['message'] = serializer.serialize('json', stud)

In contrast to the module-level function, the serializer's method does not take a target format argument, but only a queryset:

response_data['message'] = serializer.serialize(stud)
By : dhke

This video can help you solving your question :)
By: admin