Provide 'V' as alias for 'Value'?

99 views
Skip to first unread message

Adam Johnson

unread,
Apr 3, 2017, 3:58:43 AM4/3/17
to django-d...@googlegroups.com
When writing filter expressions using database functions, one is often forced to use django.db.models.Value to wrap raw values to avoid them being interpreted as column references. Value is fairly cumbersome to write when it can appear several times in a complex queryset definition, so it's common to alias it as V when importing. In fact, the database function docs do this exclusively.

Because import as is sometimes considered bad style, but the V alias is useful, I'd like to propose django.db.models having a documented internal alias like V = Value. I'm writing here because I can't think of a precedent in Django, except for backwards compatibility reasons.

--
Adam

Josh Smeaton

unread,
Apr 3, 2017, 7:15:11 AM4/3/17
to Django developers (Contributions to Django itself)
I think I proposed V as an alias back when I was writing the patch, but the rough consensus at the time was that one letter class names are a bit of an anti pattern (Q, F) that we shouldn't persist with. Aliasing V in the examples was my way of sneaking the idea through for those who chose to act similarly. I'd be ok with providing an alias, but I think examples should still import the Value name to make the code more clear what V actually refers to. 

Marc Tamlyn

unread,
Apr 5, 2017, 3:35:40 AM4/5/17
to django-d...@googlegroups.com
Given that you can always do import Value as V, I'm not sure providing an alias is necessary.

--
You received this message because you are subscribed to the Google Groups "Django developers (Contributions to Django itself)" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-developers+unsubscribe@googlegroups.com.
To post to this group, send email to django-developers@googlegroups.com.
Visit this group at https://groups.google.com/group/django-developers.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-developers/1e4d267e-7441-489f-a2ac-c23f34cd246c%40googlegroups.com.

For more options, visit https://groups.google.com/d/optout.

Reply all
Reply to author
Forward
0 new messages