Better way of doing that with less side effects. Thought it wasn't possible earlier because I misread something.
This commit is contained in:
parent
427dcc3985
commit
08ee399ea2
2 changed files with 2 additions and 5 deletions
|
|
@ -115,8 +115,6 @@ class ObjectManager(TypedObjectManager):
|
||||||
type_restriction = typeclasses and Q(db_typeclass_path__in=make_iter(typeclasses)) or Q()
|
type_restriction = typeclasses and Q(db_typeclass_path__in=make_iter(typeclasses)) or Q()
|
||||||
|
|
||||||
## This doesn't work if attribute_value is an object. Workaround below
|
## This doesn't work if attribute_value is an object. Workaround below
|
||||||
#q = self.filter(cand_restriction & type_restriction & Q(objattribute__db_key=attribute_name) & Q(objattribute__db_value=attribute_value))
|
|
||||||
#return list(q)
|
|
||||||
|
|
||||||
if isinstance(attribute_value, (basestring, int, float, bool, long)):
|
if isinstance(attribute_value, (basestring, int, float, bool, long)):
|
||||||
return self.filter(cand_restriction & type_restriction & Q(db_attributes__db_key=attribute_name, db_attributes__db_value=attribute_value))
|
return self.filter(cand_restriction & type_restriction & Q(db_attributes__db_key=attribute_name, db_attributes__db_value=attribute_value))
|
||||||
|
|
@ -126,7 +124,7 @@ class ObjectManager(TypedObjectManager):
|
||||||
if not _ATTR:
|
if not _ATTR:
|
||||||
from src.typeclasses.models import Attribute as _ATTR
|
from src.typeclasses.models import Attribute as _ATTR
|
||||||
cands = list(self.filter(cand_restriction & type_restriction & Q(db_attributes__db_key=attribute_name)))
|
cands = list(self.filter(cand_restriction & type_restriction & Q(db_attributes__db_key=attribute_name)))
|
||||||
results = [attr.db_objects.all() for attr in _ATTR.objects.filter(db_objects__in=cands, db_value=attribute_value)]
|
results = [attr.objectdb_set.all() for attr in _ATTR.objects.filter(objectdb__in=cands, db_value=attribute_value)]
|
||||||
return chain(*results)
|
return chain(*results)
|
||||||
|
|
||||||
@returns_typeclass_list
|
@returns_typeclass_list
|
||||||
|
|
|
||||||
|
|
@ -596,8 +596,7 @@ class TypedObject(SharedMemoryModel):
|
||||||
help_text="locks limit access to an entity. A lock is defined as a 'lock string' on the form 'type:lockfunctions', defining what functionality is locked and how to determine access. Not defining a lock means no access is granted.")
|
help_text="locks limit access to an entity. A lock is defined as a 'lock string' on the form 'type:lockfunctions', defining what functionality is locked and how to determine access. Not defining a lock means no access is granted.")
|
||||||
# many2many relationships
|
# many2many relationships
|
||||||
db_attributes = models.ManyToManyField(Attribute, null=True,
|
db_attributes = models.ManyToManyField(Attribute, null=True,
|
||||||
help_text='attributes on this object. An attribute can hold any pickle-able python object (see docs for special cases).',
|
help_text='attributes on this object. An attribute can hold any pickle-able python object (see docs for special cases).')
|
||||||
related_name='db_objects')
|
|
||||||
db_liteattributes = models.ManyToManyField(LiteAttribute, null=True,
|
db_liteattributes = models.ManyToManyField(LiteAttribute, null=True,
|
||||||
help_text='liteattributes on this object. A LiteAttribute holds a key, a category and a string field for simple lookups.')
|
help_text='liteattributes on this object. A LiteAttribute holds a key, a category and a string field for simple lookups.')
|
||||||
db_tags = models.ManyToManyField(Tag, null=True,
|
db_tags = models.ManyToManyField(Tag, null=True,
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue