How would you tell Django to return ImageField.url (not relative path) when seri...
source link: https://www.codesd.com/item/how-would-you-tell-django-to-return-imagefield-url-not-relative-path-when-serializing-a-model.html
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
How would you tell Django to return ImageField.url (not relative path) when serializing a model?
ImageField on the model
some_image = models.ImageField(upload_to= get_upload_path)
This is what i use for serializing:
data = serializers.serialize("json",ModelName.objects.all(),use_natural_keys=True)
the json i get for some_image is relative to the MEDIA_URL
to solve it manualy i call some_image.url, and that works fine, how do i make it so this will be the default value that the image returns when using serializers.serialize
Here are the docs for specifying which fields get serialized: https://docs.djangoproject.com/en/dev/topics/serialization/#subset-of-fields
It sounds like you should include url and all the other fields except some_image.
Related Articles
How would you do the The Dock icon to display a window when you clicked?
Analyzing the FxCop log file - how would you do it?
How can you tell whether to delete a pointer returned from a function or not
How would you inherit and replace the django template classes to create a listOfStringsField object?
Algorithm - How would you determine the minimum number of multiplications to evaluate X on power 30?
I want to write a visual studio extension to access Redmine problems. How would you recommend it?
How would you define a delayed parameter (by name) that accepts a function taking parameters?
How would you calculate all possible permutations from 0 to N in an iterative way?
How would you like EOF in bash?
How would you explain reflection to a non-programmer?
How would you upload files to a React-Relay application?
How would you generate a key that was only worth three months?
How would you get a JSONPath to all child nodes in a set of JSON objects?
How would you build this daily class?
Recommend
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK