BooleanField is_true and is_false methods
See original GitHub issueProposal
Add methods to BooleanField so that we can create expressions like MyModel.my_field.is_true()
and MyModel.my_field.is_false()
instead of MyModel.my_field == True
and MyModel.my_field == False
.
Rationale
I’m using flake8
, with a selected list of pycodestyle error codes, and using MyModel.my_field == True
triggers the E712 error, comparison to True should be ‘if cond is True:’ or ‘if cond:’.
That would be consistent with the is_null
method, which is used instead of a “MyModel.my_field == None”.
Reference implementation
peewee.BooleanField.is_true = lambda self: peewee.Expression(self, peewee.OP.EQ, True)
peewee.BooleanField.is_false = lambda self: peewee.Expression(self, peewee.OP.EQ, False)
Issue Analytics
- State:
- Created 7 years ago
- Reactions:5
- Comments:6 (3 by maintainers)
Top Results From Across the Web
BooleanField - Django Models - GeeksforGeeks
BooleanField is a true/false field. It is like a bool field in C/C+++. The default form widget for this field is CheckboxInput, ...
Read more >Unique BooleanField value in Django? - Stack Overflow
Whenever I've needed to accomplish this task, what I've done is override the save method for the model and have it check if...
Read more >Boolean field in FLOW sends EMPTY STRING when using ...
Boolean field is HIDDEN, value is FALSE; Flow sends EMPTY STRING. ... Scenario 1: Boolean field on record is TRUE.
Read more >Boolean (Java Platform SE 7 ) - Oracle Help Center
Returns a Boolean instance representing the specified boolean value. If the specified boolean value is true , this method returns Boolean.TRUE ; if...
Read more >Boolean data type - Wikipedia
In computer science, the Boolean (sometimes shortened to Bool) is a data type that has one of two possible values which is intended...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
I appreciate you taking the time to submit this issue. Unfortunately, peewee does quite a few things that many linters find egregious. I don’t use linters myself, so it doesn’t bother me and personally I’m not interested in adding code simply to satisfy flake8. Thanks for providing a reference implementation, anyone who is interested can use your code or subclass
BooleanField
and add the suggested methods.You’ve shared a nice one.