Opened 14 years ago

Closed 11 years ago

#13688 closed New feature (wontfix)

Ability to specify the field type for extra select

Reported by: jonozzz Owned by: nobody
Component: Database layer (models, ORM) Version: 1.2
Severity: Normal Keywords: extra select field types
Cc: Triage Stage: Design decision needed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

Entry.objects.extra(select={'is_recent': "pub_date > '2006-01-01'"})

should look like:

Entry.objects.extra(select={BooleanField('is_recent'): "pub_date > '2006-01-01'"})

Ideally this would map over the existing fields.

The idea is that some of the extra fields might need preparation before using them in python (like custom fields). This is done by to_python() method, but for extra fields there's no such thing.
They will always contain the raw DB data.

Change History (5)

comment:1 by Tobias McNulty, 14 years ago

Triage Stage: UnreviewedDesign decision needed

This is a feature request and I'm not sure how important it is or if it even makes sense to include. Personally I don't mind the simplicity of getting the raw result back from the DB (it's what I'd expect when using .extra()). You can always retrieve the value as a "hidden" field (e.g., '_is_recent') and add a property ('is_recent') to your model that converts the field to the appropriate type.

comment:2 by Julien Phalip, 13 years ago

Severity: Normal
Type: New feature

comment:3 by Aymeric Augustin, 12 years ago

UI/UX: unset

Change UI/UX from NULL to False.

comment:4 by Aymeric Augustin, 12 years ago

Easy pickings: unset

Change Easy pickings from NULL to False.

comment:5 by Anssi Kääriäinen, 11 years ago

Resolution: wontfix
Status: newclosed

I agree to the use case, but not to any extension to .extra(). I would rather see something like:
.annotate(is_recent=SQL("pub_date > %s", [somedate], field=BooleanField)
then you might be able to do things like .values('is_recent') or .order_by('is_recent'). Here the BooleanField case isn't that interesting, but if you have complex SQL, then being able to use it later on with the ORM as just another field seems useful.

I am closing this ticket as wontfix for the .extra() change, but I would like to see the .annotate() idea in the ORM one day...

Note: See TracTickets for help on using tickets.
Back to Top