-
Notifications
You must be signed in to change notification settings - Fork 91
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
make Readable for boolean fields more user-friendly #741
Comments
@trondhindenes For boolean readable fields, Piccolo returns the database representation of the boolean column (Sqlite result = await Band.select(Band.get_readable())
for item in result:
if item["readable"] in ["0", "f"]:
item["readable"] = "False"
else:
item["readable"] = "True"
print(result) and result is [
{
"readable":"False"
},
{
"readable":"True"
}
] I hope that's ok for you. |
Hi thanks - I assumed that was the case. I'm using readables with class methods to make piccolo-admin print nicer strings:
I just assumed there wasn't much I could do in there, but now that I actually read the code I can ofc manipulate the |
Hi - sorry for the slow reply, I managed to catch the flu over the holidays. PR #742 offers another solution: class DiscountCode(Table):
code = UUID()
active = Boolean(default=True, null=True)
@classmethod
def get_readable(cls) -> Readable:
return Readable(
template="%s - %s",
columns=[
cls.code,
SelectRaw(
"CASE WHEN active THEN 'active' ELSE 'inactive' END"
),
],
) We added What do you both think? |
@dantownsend This looks and works great and is nicer than manipulating the result. |
Nice! This more than covers my use case. I'd love to see "advanced usage" snippets like this in the docs as well |
As far as I can see, if using
Readable
andget_readable
, boolean fields are represented asf
andt
(False and True). It would be good if it was possible to represent these in a more user-friendly way - Maybe even make the default similar to Python's string representation of booleans:The text was updated successfully, but these errors were encountered: