question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

creating an empty Filter() ?

See original GitHub issue

Just for programming easiness,

f = F()

if condition:
   f = f & F(..)

Something like above is possible?

Issue Analytics

  • State:closed
  • Created 9 years ago
  • Reactions:1
  • Comments:9 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
honzakralcommented, Mar 17, 2015

@apandita some people might prefer to always have a filter instead of conditional statements, imagine:

filter = None
if cat:
    filter = F('term', category=cat)
if type:
    if filter:
        filter &= F('term', type=type)
    else:
        filter = F('term', type=type)

with an empty filter you can do:

filter = F('match_all')
if cat:
    filter &= F('term', category=cat)
if type:
    filter &= F('term', type=type)

so it’s much more straightforward

1reaction
honzakralcommented, Mar 13, 2015

Good idea - you can currently use F('match_all') that will behave exactly as you want (f == f & F('match_all'))

Do you (or anyone else) think that’s enough or we should make it a default for F()?

The same works for queries btw - Q('match_all')

Read more comments on GitHub >

github_iconTop Results From Across the Web

Filter on null, blank, or empty values | ThoughtSpot Software
Filtering on NULL and empty values is a special case, and can be tricky if your data contains more than one of these....
Read more >
Filtering for Empty or Null Values in a Django QuerySet - Chartio
Easily the most important method when working with Django models and the underlying QuerySets is the filter() method, which allows you to generate...
Read more >
Solved: Deal with empty Filter array - Power Platform Community
Solved: Hello I have a Filter array which have one item when it's true and none when its false. I'am trying to make...
Read more >
How to Filter for SQL Null or Empty String
In this video, I show you how to filter for SQL Null or Empty String in SQL Server 2012. I will also show...
Read more >
Tips and Solutions — django-filter 22.1 documentation
You can override the filter() method of a filter class to specifically check ... It would also be possible to create an empty...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found