[Django] #23363: Field length in ORM

54 views
Skip to first unread message

Django

unread,
Aug 25, 2014, 9:00:30 AM8/25/14
to django-...@googlegroups.com
#23363: Field length in ORM
----------------------------------------------+----------------------------
Reporter: qurben | Owner: nobody
Type: New feature | Status: new
Component: Database layer (models, ORM) | Version: 1.6
Severity: Normal | Keywords: ORM, order_by,
Triage Stage: Unreviewed | QuerySet
Easy pickings: 0 | Has patch: 0
| UI/UX: 0
----------------------------------------------+----------------------------
I can order a query by field length by using {{{.extra('length':
'Length(field)')}}}, but this is a problem when targeting mssql, where the
length function is {{{LEN()}}} is it possible to add this to the ORM?

I think it would be a simple addition, and I would be very happy.

--
Ticket URL: <https://code.djangoproject.com/ticket/23363>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

Django

unread,
Aug 25, 2014, 10:35:27 AM8/25/14
to django-...@googlegroups.com
#23363: Field length in ORM
-------------------------------------+-------------------------------------
Reporter: qurben | Owner: nobody
Type: New feature | Status: closed
Component: Database layer | Version: 1.6
(models, ORM) | Resolution:
Severity: Normal | worksforme

Keywords: ORM, order_by, | Triage Stage:
QuerySet | Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by shaib):

* status: new => closed
* needs_docs: => 0
* resolution: => worksforme
* needs_tests: => 0
* needs_better_patch: => 0


Comment:

Django 1.7, due to be released soon, includes a new feature:
[https://docs.djangoproject.com/en/1.7/ref/models/lookups/ Custom lookups
and transforms].

This allows you to solve the problem yourself.

If this doesn't answer your needs, please bring them up on the
DevelopersMailingList.

--
Ticket URL: <https://code.djangoproject.com/ticket/23363#comment:1>

Django

unread,
Aug 26, 2014, 4:19:47 AM8/26/14
to django-...@googlegroups.com
#23363: Field length in ORM
-------------------------------------+-------------------------------------
Reporter: qurben | Owner: nobody

Type: New feature | Status: closed
Component: Database layer | Version: 1.6
(models, ORM) | Resolution:
Severity: Normal | worksforme
Keywords: ORM, order_by, | Triage Stage:
QuerySet | Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------

Comment (by jarshwah):

I don't think custom lookups and transforms works for this use case. The
ticket reporter wants to include that information in the select list.
Transforms and Lookups are only really used in filter clauses at the
moment.

There is a PR that will allow this kind of functionality here:
https://github.com/django/django/pull/2496

And to implement the length function, you'd create an object such as:

{{{
class Length(Func):
function = 'LENGTH'

def as_mssql(self, compiler, query):
self.function = 'LEN'
return super(Length, self).as_sql(compiler, query)

MyModel.objects.annotate(length=Length('myfield'))
}}}

I'm reopening on the basis that lookups and transforms don't solve the
problem.

--
Ticket URL: <https://code.djangoproject.com/ticket/23363#comment:2>

Django

unread,
Aug 26, 2014, 4:20:25 AM8/26/14
to django-...@googlegroups.com
#23363: Field length in ORM
-------------------------------------+-------------------------------------

Reporter: qurben | Owner: nobody
Type: New feature | Status: new
Component: Database layer | Version: master
(models, ORM) | Resolution:
Severity: Normal | Triage Stage:
Keywords: ORM, order_by, | Unreviewed
QuerySet | Needs documentation: 0
Has patch: 0 | Patch needs improvement: 0
Needs tests: 0 | UI/UX: 0
Easy pickings: 0 |
-------------------------------------+-------------------------------------
Changes (by jarshwah):

* status: closed => new
* version: 1.6 => master
* resolution: worksforme =>


--
Ticket URL: <https://code.djangoproject.com/ticket/23363#comment:3>

Django

unread,
Aug 31, 2014, 2:56:13 PM8/31/14
to django-...@googlegroups.com
#23363: Field length in ORM
-------------------------------------+-------------------------------------

Reporter: qurben | Owner: nobody
Type: New feature | Status: new
Component: Database layer | Version: master
(models, ORM) | Resolution:
Severity: Normal | Triage Stage:
Keywords: ORM, order_by, | Unreviewed
QuerySet | Needs documentation: 0
Has patch: 0 | Patch needs improvement: 0
Needs tests: 0 | UI/UX: 0
Easy pickings: 0 |
-------------------------------------+-------------------------------------

Comment (by aaugustin):

Josh, I gather from your comment that this is covered by #14030, isn't it?

If so, this ticket can be closed as a duplicate. If not, could you clarify
what needs to be done to close it?

--
Ticket URL: <https://code.djangoproject.com/ticket/23363#comment:4>

Django

unread,
Aug 31, 2014, 6:17:11 PM8/31/14
to django-...@googlegroups.com
#23363: Field length in ORM
-------------------------------------+-------------------------------------

Reporter: qurben | Owner: nobody
Type: New feature | Status: new
Component: Database layer | Version: master
(models, ORM) | Resolution:
Severity: Normal | Triage Stage:
Keywords: ORM, order_by, | Unreviewed
QuerySet | Needs documentation: 0
Has patch: 0 | Patch needs improvement: 0
Needs tests: 0 | UI/UX: 0
Easy pickings: 0 |
-------------------------------------+-------------------------------------

Comment (by jarshwah):

I can't seem to find a ticket requesting an implementation of custom
functions (other than extensions to .extra()). #14030 will allow this
feature request to be implemented, but the original scope of 14030 was to
allow F() objects to be composed with aggregates.

I think we should open a new ticket that defines a list of functions to be
implemented by django (pending #14030), and close off any related tickets
such as this one as duplicates/wontfixes. I'm happy to open that new
ticket, but will have to do so later in the day.

--
Ticket URL: <https://code.djangoproject.com/ticket/23363#comment:5>

Django

unread,
Oct 23, 2014, 3:56:16 PM10/23/14
to django-...@googlegroups.com
#23363: Field length in ORM
-------------------------------------+-------------------------------------

Reporter: qurben | Owner: nobody
Type: New feature | Status: new
Component: Database layer | Version: master
(models, ORM) | Resolution:
Severity: Normal | Triage Stage:
Keywords: ORM, order_by, | Unreviewed
QuerySet | Needs documentation: 0
Has patch: 0 | Patch needs improvement: 0
Needs tests: 0 | UI/UX: 0
Easy pickings: 0 |
-------------------------------------+-------------------------------------
Changes (by timgraham):

* cc: jarshwah (added)


Comment:

Josh, just wanted to remind you about following up on this if you can.

--
Ticket URL: <https://code.djangoproject.com/ticket/23363#comment:6>

Django

unread,
Oct 24, 2014, 6:41:41 AM10/24/14
to django-...@googlegroups.com
#23363: Field length in ORM
-------------------------------------+-------------------------------------

Reporter: qurben | Owner: nobody
Type: New feature | Status: new
Component: Database layer | Version: master
(models, ORM) | Resolution:
Severity: Normal | Triage Stage:
Keywords: ORM, order_by, | Unreviewed
QuerySet | Needs documentation: 0
Has patch: 0 | Patch needs improvement: 0
Needs tests: 0 | UI/UX: 0
Easy pickings: 0 |
-------------------------------------+-------------------------------------

Comment (by jarshwah):

Thanks Tim. I've resumed the discussion on the mailing list here:
https://groups.google.com/forum/#!searchin/django-developers/functions
/django-developers/HggiPzwkono/dsnx3BuXpnkJ

Once we reach some sort of consensus or enough time passes without
response, I'll go ahead and create the ticket. I'll bookmark this so I
remember to come back to it.

--
Ticket URL: <https://code.djangoproject.com/ticket/23363#comment:7>

Django

unread,
Nov 2, 2014, 6:14:13 PM11/2/14
to django-...@googlegroups.com
#23363: Field length in ORM
-------------------------------------+-------------------------------------
Reporter: qurben | Owner: nobody
Type: New feature | Status: closed

Component: Database layer | Version: master
(models, ORM) | Resolution: duplicate

Severity: Normal | Triage Stage:
Keywords: ORM, order_by, | Unreviewed
QuerySet | Needs documentation: 0
Has patch: 0 | Patch needs improvement: 0
Needs tests: 0 | UI/UX: 0
Easy pickings: 0 |
-------------------------------------+-------------------------------------
Changes (by jarshwah):

* status: new => closed
* resolution: => duplicate


--
Ticket URL: <https://code.djangoproject.com/ticket/23363#comment:8>

Django

unread,
Nov 2, 2014, 6:14:32 PM11/2/14
to django-...@googlegroups.com
#23363: Field length in ORM
-------------------------------------+-------------------------------------
Reporter: qurben | Owner: nobody

Type: New feature | Status: closed
Component: Database layer | Version: master
(models, ORM) | Resolution: duplicate
Severity: Normal | Triage Stage:
Keywords: ORM, order_by, | Unreviewed
QuerySet | Needs documentation: 0
Has patch: 0 | Patch needs improvement: 0
Needs tests: 0 | UI/UX: 0
Easy pickings: 0 |
-------------------------------------+-------------------------------------

Comment (by jarshwah):

#23753 will take over for this ticket.

--
Ticket URL: <https://code.djangoproject.com/ticket/23363#comment:9>

Reply all
Reply to author
Forward
0 new messages