Fixed a logical error in obj.manager causing it to fail to find arbitrary db_>fieldname>. Resolves Issue 373.

This commit is contained in:
Griatch 2013-05-21 14:29:50 +02:00
parent bda5d88c24
commit efdb954491
4 changed files with 13 additions and 7 deletions

View file

@ -153,8 +153,9 @@ class ObjectManager(TypedObjectManager):
"""
property_name = "db_%s" % property_name.lstrip('db_')
cand_restriction = candidates and Q(pk__in=[_GA(obj, "id") for obj in make_iter(candidates) if obj]) or Q()
querykwargs = {property_name:None}
try:
return list(self.filter(cand_restriction).exclude(Q(property_name=None)))
return list(self.filter(cand_restriction).exclude(Q(**querykwargs)))
except exceptions.FieldError:
return []
@ -169,10 +170,11 @@ class ObjectManager(TypedObjectManager):
property_value = to_unicode(property_value)
if isinstance(property_name, basestring):
property_name = "db_%s" % property_name.lstrip('db_')
querykwargs = {property_name:property_value}
cand_restriction = candidates and Q(pk__in=[_GA(obj, "id") for obj in make_iter(candidates) if obj]) or Q()
type_restriction = typeclasses and Q(db_typeclass_path__in=make_iter(typeclasses)) or Q()
try:
return list(self.filter(cand_restriction & type_restriction & Q(property_name=property_value)))
return list(self.filter(cand_restriction & type_restriction & Q(**querykwargs)))
except exceptions.FieldError:
return []
@ -310,7 +312,8 @@ class ObjectManager(TypedObjectManager):
# no matches found - check if we are dealing with N-keyword query - if so, strip it.
match_number, searchdata = _AT_MULTIMATCH_INPUT(searchdata)
# run search again, with the exactness set by call
matches = _searcher(searchdata, candidates, typeclass, exact=exact)
if match_number != None or not exact:
matches = _searcher(searchdata, candidates, typeclass, exact=exact)
# deal with result
if len(matches) > 1 and match_number != None:

View file

@ -575,7 +575,10 @@ class ObjectDB(TypedObject):
be a list of typeclasses for a broader search.
location (Object): Specify a location to search, if different from the self's given location
plus its contents. This can also be a list of locations.
attribute_name (str): Use this named Attribute to match searchdata against, instead of object.key.
attribute_name (str): Define which property to search. If set, no key+alias search will be performed. This can be used to
search database fields (db_ will be automatically appended), and if that fails, it will try to
return objects having Attributes with this name and value equal to searchdata. A special
use is to search for "key" here if you want to do a key-search without including aliases.
quiet (bool) - don't display default error messages - return multiple matches as a list and
no matches as None. If not set (default), will echo error messages and return None.
exact (bool) - if unset (default) - prefers to match to beginning of string rather than not matching