Exemplo n.º 1
0
 def get_extra_restriction(self, where_class, alias, remote_alias):
     field = self.rel.to._meta.get_field_by_name(self.content_type_field_name)[0]
     contenttype_pk = self.get_content_type().pk
     cond = where_class()
     lookup = field.get_lookup('exact')(Col(remote_alias, field, field), contenttype_pk)
     cond.add(lookup, 'AND')
     return cond
Exemplo n.º 2
0
    def wrapper(self, where_class, alias, lhs):
        cond = func(self, where_class, alias, lhs)

        from .models import PermanentModel
        if not issubclass(self.model, PermanentModel) or issubclass(
                where_class, AllWhereNode):
            return cond

        if issubclass(where_class, DeletedWhereNode):
            cond = cond or ~where_class()
        else:
            cond = cond or where_class()

        if django.VERSION < (1, 8, 0):
            field = self.model._meta.get_field_by_name(settings.FIELD)[0]
        else:
            field = self.model._meta.get_field(settings.FIELD)

        if django.VERSION < (1, 7, 0):
            from django.db.models.sql.where import Constraint
            if settings.FIELD_DEFAULT is None:
                lookup = Constraint(lhs, settings.FIELD, field), 'isnull', True
            else:
                lookup = Constraint(lhs, alias,
                                    field), 'exact', settings.FIELD_DEFAULT

        else:
            if django.VERSION < (1, 8, 0):
                from django.db.models.sql.datastructures import Col
            else:
                from django.db.models.expressions import Col

            if settings.FIELD_DEFAULT is None:
                lookup = field.get_lookup('isnull')(Col(lhs, field, field),
                                                    True)
            else:
                lookup = field.get_lookup('exact')(Col(lhs, field, field),
                                                   settings.FIELD_DEFAULT)

        cond.add(lookup, 'AND')

        return cond