Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Commit e3f065 Breaks Custom Serializers for Custom QuerySets #1

Open
tdavis opened this issue Jun 4, 2009 · 2 comments
Open

Commit e3f065 Breaks Custom Serializers for Custom QuerySets #1

tdavis opened this issue Jun 4, 2009 · 2 comments

Comments

@tdavis
Copy link

tdavis commented Jun 4, 2009

One of my models uses a custom QuerySet and Manager. When I return a SerializableResponse of "CustomQuerySet", my object serializer is ignored and instead a response is returned like:

<customqueryset>
    <field1>val1</field1>
    <field2>val2</field2>
    ...
</customqueryset>

This was not the case prior to the latest commit; reverting to the previous commit fixed the issue.

@gvangool
Copy link

gvangool commented Jun 7, 2009

Could you provide me with a full example? Since there is currently no test suite it's hard to test anything, but what we use.

In my fork, I made modification that allow for more granular control of the output and serialization of errors.

@tdavis
Copy link
Author

tdavis commented Jun 7, 2009

Sure. I just made this up, but it should give you a good enough idea:

# app/models.py
from django.db import models

class CustomQuerySet(models.query.queryset):
    pass

class CustomManager(models.Manager):
    def get_query_set(self):
        return CustomQuerySet(self.model)

class MyModel(models.Model):
    public_field = models.BooleanField(default=True)
    private_field = models.BooleanField(default=False)
    objects = CustomManager()


# api/models.py (or whatever)
from app.models import MyModel
from wapi import serializers
from wapi.responses import SerializableResponse

class AppApi(object):
    def ns__method(self, request, args):
        return SerializableResponse(MyModel.objects.all())

class MyModelSerializer(serializers.Serializer):
    serializes = MyModel

    @serializers.objname('record')
    def default(self, obj, **kwargs):
        return {
            'public': obj.public_field
        }

# Expected output
"""
...
<record>
    <public>True</public>
</record>
...
"""

# Real output
"""
...
<customqueryset>
    <public_field>True</public_field>
    <private_field>False</private_field>
</customqueryset>
...
"""

I will check out your fork too, thanks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants