From eac47766844b90e7d3269e7a8c012eee34ec0093 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Anssi=20K=C3=A4=C3=A4ri=C3=A4inen?= Date: Sun, 1 Dec 2013 02:22:30 +0200 Subject: [PATCH] Minor cleanup of Lookup API --- django/db/models/lookups.py | 11 +---------- docs/ref/models/lookups.txt | 15 ++++----------- 2 files changed, 5 insertions(+), 21 deletions(-) diff --git a/django/db/models/lookups.py b/django/db/models/lookups.py index b096a20e88..010d77a76a 100644 --- a/django/db/models/lookups.py +++ b/django/db/models/lookups.py @@ -1,6 +1,5 @@ from copy import copy -from django.core.exceptions import FieldError from django.conf import settings from django.utils import timezone from django.utils.functional import cached_property @@ -29,18 +28,10 @@ class Extract(object): class Lookup(object): lookup_name = None - extract_class = None def __init__(self, lhs, rhs): self.lhs, self.rhs = lhs, rhs - if rhs is None: - if not self.extract_class: - raise FieldError("Lookup '%s' doesn't support nesting." % self.lookup_name) - else: - self.rhs = self.get_prep_lookup() - - def get_extract(self): - return self.extract_class(self.lhs) + self.rhs = self.get_prep_lookup() def get_prep_lookup(self): return self.lhs.output_type.get_prep_lookup(self.lookup_name, self.rhs) diff --git a/docs/ref/models/lookups.txt b/docs/ref/models/lookups.txt index b5dc5c20d1..959c70cb14 100644 --- a/docs/ref/models/lookups.txt +++ b/docs/ref/models/lookups.txt @@ -93,16 +93,9 @@ The process_rhs method is used to convert the right hand side into query string. The rhs is the value given in the filter clause. It can be a raw value to compare agains, a F() reference to another field or even a QuerySet. -.. method:: get_extract() - -The get_extract method is used in nested lookups. It must return an Extract instance. - -.. classattribute:: Lookup.extract_class - -The default implementation of get_extract() will return an instance of extract_class. - -In addition there are some private methods - that is, implementing just the above -mentioned attributes and methods is not enough, you must subclass Lookup instead. +In addition the Lookup class has some private methods - that is, implementing +just the above mentioned attributes and methods is not enough, instead you +should subclass Lookup. The Extract class ~~~~~~~~~~~~~~~~~ @@ -112,7 +105,7 @@ For example you could have an Extract that procudes modulo 3 of the given value. In SQL this would be something like "author"."age" % 3. Extracts are used in nested lookups. The Extract class must implement the query -part interface. +part interface. In addition the Extract should must lookup_name attribute. A simple Lookup example ~~~~~~~~~~~~~~~~~~~~~~~