Python lesson I learned today - use "is None" when you want to check if something exists. I had heard this advice before but it was so easy for me to use "if not x:".
Here's where it hurt:
The optional qs parameter is for a Django QuerySet ORM object which was intended for some subset of the user's notes like only files ( self.notes.filter(type='file') ). Versatile!
However, if the QuerySet was an empty result set, the "if not qs" evaluated to False. Then qs became the set of all notes. Exactly NOT what I wanted! Wow. Terrible.
The correct condition is "if qs is None" like so:
Anyways, I hope this helps someone else.
Here's where it hurt:
def get_notes(qs=None):
if not qs:
qs = self.notes.all()
...
The optional qs parameter is for a Django QuerySet ORM object which was intended for some subset of the user's notes like only files ( self.notes.filter(type='file') ). Versatile!
However, if the QuerySet was an empty result set, the "if not qs" evaluated to False. Then qs became the set of all notes. Exactly NOT what I wanted! Wow. Terrible.
The correct condition is "if qs is None" like so:
def get_notes(qs=None):
if qs is None: # no predefined queryset
qs = self.notes.all()
...
Anyways, I hope this helps someone else.