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

ImageSpecField not getting serialized #290

Closed
exaroth opened this issue Aug 10, 2014 · 4 comments
Closed

ImageSpecField not getting serialized #290

exaroth opened this issue Aug 10, 2014 · 4 comments

Comments

@exaroth
Copy link

exaroth commented Aug 10, 2014

Hello there,

I'm writing a simple image gallery site in django, and im using Imagekit for generating thumbnails, however i've got a problem when serializing data into JSON for an AJAX view, namely the ImageSpecField is getting ommited when data is being serialized (by django built in serializer), is this a bug or maybe i'm missing something here? I think by default it should return instance.thumbnail.url when the field is being serialized (assuming thumbnail is ImageSpecField)

@matthewwithanm
Copy link
Owner

Sorry, I'm not really familiar with Django's serializers. I wouldn't have expected serialization to work by default on custom field types so I'd say this is more of a feature request than a bug, though it is something we should support.

@exaroth
Copy link
Author

exaroth commented Sep 23, 2014

Thanks for the reply,
I solved this problem by manually defining a method on the model which converts it to dictionary which then gets serialized into JSON, this way I was able to specify custom attributes of the model to be serialized.

@exaroth exaroth closed this as completed Sep 23, 2014
@ChillyBwoy
Copy link

Hello.
I have the same problem with ImageSpecField – caffeinehit/django-oauth2-provider#101

All you need is to add method value_to_string to ImageSpecField class
https://docs.djangoproject.com/en/1.6/howto/custom-model-fields/#django.db.models.Field.value_to_string

@matthewwithanm
Copy link
Owner

Thanks for the tip @ChillyBwoy! Unfortunately, it seems like the serializers only use the stuff in local_fields and virtual fields like ImageSpecField don't get added to that. If you've got any ideas, though, let me know!

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

3 participants