Skip to content

Commit

Permalink
Fix issue with id field adding to model instance dictionary. Prettier…
Browse files Browse the repository at this point in the history
… Query class __str__ method.
  • Loading branch information
GrAndSE committed May 2, 2012
1 parent de8eeab commit dd84b3d
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 3 deletions.
5 changes: 3 additions & 2 deletions lighty/db/models.py
Expand Up @@ -114,12 +114,13 @@ def __init__(self, key_name=None, is_new=True, **kwds):
"""
self._app = None
self._key_name = key_name or '_id'
self._is_saved = not is_new
# Set the default values for unsetted fields
self._is_saved = not is_new or self._key_name in kwds
cls = self.__class__
for field_name in self._fields:
setattr(self, field_name, kwds[field_name] if field_name in kwds
else cls.__dict__[field_name].default)
if self._is_saved:
setattr(self, self._key_name, kwds[self._key_name])

def key(self):
"""Unique key for this entity.
Expand Down
2 changes: 1 addition & 1 deletion lighty/db/query.py
Expand Up @@ -99,7 +99,7 @@ def __str__(self):
>>> str(Query(ModelClass.field > 0))
SELECT * FROM modelclass WHERE field > 0
'''
if self._from_query is None:
if self._from_query is None or self._from_query.operand is None:
if self.operation == operator.__not__:
return '%s (%s)' % (operator.__not__, str(self.operation))
return str(self.operand)
Expand Down

0 comments on commit dd84b3d

Please sign in to comment.