These are chat archives for django/django

Jan 2018
Jan 19 2018 03:26
@deepio thank you :+1:
Jan 19 2018 03:27

Hi, anyone can help me finding solution for my problem?
I have raw sql to call stored function on database, let's say:

query = "SELECT * FROM videos JOIN user ON"
discList = Video.objects.raw(query)

and I have 2 serializer, to make it nested serializer:

class UserSerializer(serializers.Serializer):
    id = serializers.IntegerField(read_only=True)
    email = serializers.CharField(read_only=True)
    photo = serializers.CharField(read_only=True)

class VideoSerializer(serializers.Serializer):
    id = serializers.CharField(read_only=True)
    user = UserSerializer(read_only=True)
    length = serializers.CharField(read_only=True)
    thumbnail = serializers.URLField(read_only=True)

I activate the log for my database, it keep doing select USER table each of video, I want the serializer can recognize I have JOIN it, how can I fix this? Please help and thanks :smile:

Jan 19 2018 03:50

why am i getting following error?

TypeError: expected str, bytes or os.PathLike object, not tuple

when i run python collectstatic i get above error
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
location = lambda x: os.path.join(BASE_DIR, x)

STATIC_URL = '/static/'
STATIC_ROOT = (location('public/'),)
STATICFILES_DIRS = (location('static/'),)

MEDIA_URL = "/media/"
MEDIA_ROOT = location('public/media')
Jan 19 2018 05:13
@SanskarSans because you are assigning value to STATIC_ROOT as tuple (location('public/'),)
just try atleast assign STATIC_ROOT = location('public/')
the same goes for STATICFILES_DIRS
Jan 19 2018 05:52

why am I getting error when using:

from django.db.models.query import prefetch_related_objects
#raw querysets do not have len()
#thats why we need to evaluate them to list
videos = list(Video.objects.raw("select * from video join user on video.user_id ="))
prefetch_related_objects(videos, ['user'])

the error is:

unhashable type: 'list'
Jan 19 2018 05:54
Thanks @badcoder28 it worked but the STATICFILES_DIRS has to be tuple
Alex Daigle
Jan 19 2018 06:00
@sukianto can you give more of the error message?
Jan 19 2018 06:17
@deepio Hmm, the code is different OK, I will provide the real code, and actually the error message is just like that, I will provide the traceback
                from django.db.models.query import prefetch_related_objects
                query = "SELECT * FROM peeqr_fn_get_discovery_recomended_by_score(" + \
                        str( + \
                        ") as drbs JOIN accounts_user au ON OFFSET " + \
                        str(offset) + " LIMIT " + str(limit)

                discoverlist = list(Video.objects.raw(query))
                discoverlist = prefetch_related_objects(discoverlist, ['user'])

File "//anaconda/lib/python3.4/site-packages/django/core/handlers/" in inner
  39.             response = get_response(request)

File "//anaconda/lib/python3.4/site-packages/django/core/handlers/" in _get_response
  187.                 response = self.process_exception_by_middleware(e, request)

File "//anaconda/lib/python3.4/site-packages/django/core/handlers/" in _get_response
  185.                 response = wrapped_callback(request, *callback_args, **callback_kwargs)

File "//anaconda/lib/python3.4/site-packages/django/views/decorators/" in wrapped_view
  58.         return view_func(*args, **kwargs)

File "//anaconda/lib/python3.4/site-packages/rest_framework/" in view
  83.             return self.dispatch(request, *args, **kwargs)

File "//anaconda/lib/python3.4/site-packages/rest_framework/" in dispatch
  477.             response = self.handle_exception(exc)

File "//anaconda/lib/python3.4/site-packages/rest_framework/" in handle_exception
  437.             self.raise_uncaught_exception(exc)

File "//anaconda/lib/python3.4/site-packages/rest_framework/" in dispatch
  474.             response = handler(request, *args, **kwargs)

File "/Users/lususlab/Desktop/work/peeqr-backend-omg/videos/views_v1_2/" in discover
  2831.                 discoverlist = prefetch_related_objects(discoverlist, ['user'])

File "//anaconda/lib/python3.4/site-packages/django/db/models/" in prefetch_related_objects
  1408.         if lookup.prefetch_to in done_queries: