Closed elcolie closed 6 years ago
Right now I have to workaround by this. It is not prefect because I have to add my own http://domain.com
by myself
import logging
from rest_framework import serializers
from poinkbackend.apps.branches.models import Branch
from poinkbackend.apps.menus.models import Menu
logger = logging.getLogger('django')
class MenuSerializer(serializers.ModelSerializer):
thumbnail = serializers.SerializerMethodField(read_only=True)
class Meta:
model = Menu
fields = [
'id',
'image',
'thumbnail',
'name',
'description',
'size',
'branch',
'note',
]
read_only_fields = [
'id',
]
def get_thumbnail(self, menu: Menu):
return menu.thumbnail.url
def validate_branch(self, branch: Branch):
user = self.context['request'].user
if branch not in Branch.objects.filter(company=user.userprofile.selected_company):
msg = f'{user} select non-exist branch in {user.userprofile.selected_company}'
raise serializers.ValidationError(detail=msg)
return branch
The error in /api/menus/
is not related to django-imagekit at all. This looks like utf16 encoding instead of utf8 or something similar.
I didn't get this about http://domain.com
. Can you elaborate?
The only problem releated to django-imagekit
is probably about your admin. I'm saying probably because I don't know how your definition of the admin looks like. Can you show some code of your admin how you define the thumbnail?
Here is my admin.py
from django.contrib import admin
from poinkbackend.apps.menus.models import Menu
class MenuAdmin(admin.ModelAdmin):
__basic_fields = ['id', 'name', 'image', 'thumbnail', 'description', 'size', 'branch']
list_display = __basic_fields
search_fields = __basic_fields
admin.site.register(Menu, MenuAdmin)
The problme also occur when I use with django rest
image
has absolute url
thumbnail
has not. At here this is want I mean http
and domain
. I am not sure how to address this properly. I rarely found this issue.
// 20180219225739
// http://localhost:8000/api/menus/1/?format=json
{
"id": 1,
"image": "http://localhost:8000/media/uc.png",
"thumbnail": "/media/CACHE/images/uc/46fbbe0a74051b68a53c0f5536f0af88.jpg",
"name": "kOzGVMbxqIjEpVvFdNSQwywDHAujbVOECjrQuoBzZmAWUKZoKZ",
"name_th": "ESwTyAYVuGxvvcUMCcZjyYtFKbgtIQkeqYGDCoNuuHsvsXnhpd",
"description": "bmnqipAJhbMmukCTebksnQeuAxCiWRPzzUnTlbQtqdVAwHGcfrsFRTTEfTlWyJuodCIQvOAvHrXHNNwMoXvvfXhvlNyJMVNnVivIOqfXyELBAEkHhrJVlUBBICIgwWshgpagvIIaMcJpvuHvNQPLIc",
"description_th": "DjpnqGOqPSlVGpJOUvvBnlPZyYpgtgJeaPkqjJDWRCVrQgtzaPaImdwZKBLyiYlgjaqhLlgRnPlNHqAFtZZSAndxrFwNIhFKEOdzNoPvvGwXgkfCZXuNXXfbINYUfixRPdYrXrxWESwYCoZmWIfSQs",
"size": "M",
"branch": 1,
"note": {
"L": 30,
"M": 20,
"S": 10,
"XL": 40
}
}
FYI. I had followed the docs. But it does not solve my problem. Here is what I did
from django.contrib import admin
from imagekit.admin import AdminThumbnail
from poinkbackend.apps.menus.models import Menu
class MenuAdmin(admin.ModelAdmin):
admin_thumbnail = AdminThumbnail(image_field='thumbnail')
__basic_fields = ['id', 'name', 'image', 'thumbnail', 'description', 'size', 'branch']
list_display = __basic_fields
search_fields = __basic_fields
admin.site.register(Menu, MenuAdmin)
thumbnail
does not show the url
when I hover my pointer
Let me open an new issue with simplify example. I really wants to study how to improve django packages so much.
Try adding this on your settings.py file
AWS_S3_SIGNATURE_VERSION = 's3v4'
AWS_QUERYSTRING_AUTH = False
AWS_S3_FILE_OVERWRITE = True
Hi. I successfully add my record by![image](https://user-images.githubusercontent.com/18206728/36367509-8d8a3bbe-1585-11e8-8f28-3a49fd095288.png)
DjangoAdmin
page.Then I would like to test with with my![image](https://user-images.githubusercontent.com/18206728/36367552-c4a3480c-1585-11e8-810a-05e8313364e2.png)
Django REST Framework
Problem is as belowQuestions:
url
. Then I can easily click the linkSoftware: