-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #111 from uncovertruth/feature/migrate_to_complement
Migrate to complement
- Loading branch information
Showing
7 changed files
with
36 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,6 +2,6 @@ | |
|
||
__author__ = """UNCOVER TRUTH Inc.""" | ||
__email__ = '[email protected]' | ||
__version__ = '0.1.1' | ||
__version__ = '0.2.0' | ||
|
||
default_app_config = 'lookup_extensions.apps.LookupExtensionsConfig' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,3 @@ | ||
from .exists import * # noqa F401,F403 | ||
from .exregex import * # noqa F401,F403 | ||
from .negate import * # noqa F401,F403 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
from django.db.models import Exists | ||
from django.db.models.fields import Field | ||
from django.db.models.lookups import ( | ||
BuiltinLookup, | ||
FieldGetDbPrepValueMixin, | ||
) | ||
|
||
|
||
@Field.register_lookup | ||
class Complement(FieldGetDbPrepValueMixin, BuiltinLookup): | ||
lookup_name = 'complement' | ||
|
||
def process_rhs(self, compiler, connection): | ||
if self.rhs_is_direct_value() or not isinstance(self.rhs, Exists): | ||
raise ValueError("Exists subqueries are required") | ||
|
||
db_rhs = getattr(self.rhs, '_db', None) | ||
if db_rhs is not None and db_rhs != connection.alias: | ||
raise ValueError("Subqueries aren't allowed across different databases") | ||
|
||
return super(Complement, self).process_rhs(compiler, connection) | ||
|
||
def as_sql(self, compiler, connection): | ||
return self.process_rhs(compiler, connection) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters