File: compat.py

package info (click to toggle)
drf-extensions 0.4.0-1.1
  • links: PTS
  • area: main
  • in suites: buster
  • size: 1,480 kB
  • sloc: python: 7,204; makefile: 14
file content (19 lines) | stat: -rw-r--r-- 642 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
"""
The `compat` module provides support for backwards compatibility with older
versions of django/python, and compatibility wrappers around optional packages.
"""
from __future__ import unicode_literals

from django.utils import six


# handle different QuerySet representations
def queryset_to_value_list(queryset):
    assert isinstance(queryset, six.string_types)

    # django 1.10 introduces syntax "<QuerySet [(#1), (#2), ...]>"
    # we extract only the list of tuples from the string
    idx_bracket_open = queryset.find(u'[')
    idx_bracket_close = queryset.rfind(u']')

    return queryset[idx_bracket_open:idx_bracket_close + 1]