# Path: djangoql/ast.py
# class Comparison(Operator):
#     pass
# 
# class Const(Node):
#     def __init__(self, value):
#         self.value = value
# 
# class List(Node):
#     def __init__(self, items):
#         self.items = items
# 
#     @property
#     def value(self):
#         return [i.value for i in self.items]
# 
# class Logical(Operator):
#     pass
# 
# class Name(Node):
#     def __init__(self, parts):
#         if isinstance(parts, list):
#             self.parts = parts
#         elif isinstance(parts, tuple):
#             self.parts = list(parts)
#         else:
#             self.parts = [parts]
# 
#     @property
#     def value(self):
#         return '.'.join(self.parts)
# 
# class Node(object):
#     def __str__(self):
#         children = []
#         for k, v in self.__dict__.items():
#             if isinstance(v, (list, tuple)):
#                 v = '[%s]' % ', '.join([text_type(v) for v in v if v])
#             children.append('%s=%s' % (k, v))
#         return '<%s%s%s>' % (
#             self.__class__.__name__,
#             ': ' if children else '',
#             ', '.join(children),
#         )
# 
#     __repr__ = __str__
# 
#     def __eq__(self, other):
#         if not isinstance(other, self.__class__):
#             return False
#         for k, v in self.__dict__.items():
#             if getattr(other, k) != v:
#                 return False
#         return True
# 
#     def __ne__(self, other):
#         return not self.__eq__(other)
# 
# Path: djangoql/compat.py
# PY2 = sys.version_info.major == 2
# 
# Path: djangoql/exceptions.py
# class DjangoQLSchemaError(DjangoQLError):
#     pass


import inspect
import warnings
from collections import OrderedDict, deque
from datetime import datetime
from decimal import Decimal
from django.conf import settings
from django.core.exceptions import FieldDoesNotExist
from django.db import models
from django.db.models import ManyToManyRel, ManyToOneRel
from django.db.models.fields.related import ForeignObjectRel
from django.utils.timezone import get_current_timezone
from .ast import Comparison, Const, List, Logical, Name, Node
from .compat import text_type
from .exceptions import DjangoQLSchemaError
        from .serializers import DjangoQLSchemaSerializer
    value_types_description = 'floating point numbers'


class StrField(DjangoQLField):
    type = 'str'
    value_types = [text_type]
    value_types_description = 'strings'

    def get_options(self, search):
        choice_options = super(StrField, self).get_options(search)
        if choice_options:
            return choice_options
        lookup = {}
        if search:
            lookup['%s__icontains' % self.name] = search
        return self.model.objects\
            .filter(**lookup)\
            .order_by(self.name)\
            .values_list(self.name, flat=True)\
            .distinct()


class BoolField(DjangoQLField):
    type = 'bool'
    value_types = [bool]
    value_types_description = 'True or False'


class DateField(DjangoQLField):
    type = 'date'

# Path: djangoql/ast.py
# class Comparison(Operator):
#     pass
# 
# class Const(Node):
#     def __init__(self, value):
#         self.value = value
# 
# class List(Node):
#     def __init__(self, items):
#         self.items = items
# 
#     @property
#     def value(self):
#         return [i.value for i in self.items]
# 
# class Logical(Operator):
#     pass
# 
# class Name(Node):
#     def __init__(self, parts):
#         if isinstance(parts, list):
#             self.parts = parts
#         elif isinstance(parts, tuple):
#             self.parts = list(parts)
#         else:
#             self.parts = [parts]
# 
#     @property
#     def value(self):
#         return '.'.join(self.parts)
# 
# class Node(object):
#     def __str__(self):
#         children = []
#         for k, v in self.__dict__.items():
#             if isinstance(v, (list, tuple)):
#                 v = '[%s]' % ', '.join([text_type(v) for v in v if v])
#             children.append('%s=%s' % (k, v))
#         return '<%s%s%s>' % (
#             self.__class__.__name__,
#             ': ' if children else '',
#             ', '.join(children),
#         )
# 
#     __repr__ = __str__
# 
#     def __eq__(self, other):
#         if not isinstance(other, self.__class__):
#             return False
#         for k, v in self.__dict__.items():
#             if getattr(other, k) != v:
#                 return False
#         return True
# 
#     def __ne__(self, other):
#         return not self.__eq__(other)
# 
# Path: djangoql/compat.py
# PY2 = sys.version_info.major == 2
# 
# Path: djangoql/exceptions.py
# class DjangoQLSchemaError(DjangoQLError):
#     pass


# Path: djangoql/schema.py
import inspect
import warnings
from collections import OrderedDict, deque
from datetime import datetime
from decimal import Decimal
from django.conf import settings
from django.core.exceptions import FieldDoesNotExist
from django.db import models
from django.db.models import ManyToManyRel, ManyToOneRel
from django.db.models.fields.related import ForeignObjectRel
from django.utils.timezone import get_current_timezone
from .ast import Comparison, Const, List, Logical, Name, Node
from .compat import text_type
from .exceptions import DjangoQLSchemaError
        from .serializers import DjangoQLSchemaSerializer

    value_types_description = 'floating point numbers'


class StrField(DjangoQLField):
    type = 'str'
    value_types = [text_type]
    value_types_description = 'strings'

    def get_options(self, search):
        choice_options = super(StrField, self).get_options(search)
        if choice_options:
            return choice_options
        lookup = {}
        if search:
            lookup['%s__icontains' % self.name] = search
        return self.model.objects\
            .filter(**lookup)\
            .order_by(self.name)\
            .values_list(self.name, flat=True)\
            .distinct()


class BoolField(DjangoQLField):
    type = 'bool'
    value_types = [bool]
    value_types_description = 'True or False'


class DateField(DjangoQLField):
    type = 'date'

    value_types = [text_type]