Opened 5 years ago

Closed 2 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 Changed 5 years ago by tobias

  • Needs documentation unset
  • Needs tests unset
  • Patch needs improvement unset
  • Triage Stage changed from Unreviewed to Design 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 Changed 4 years ago by julien

  • Severity set to Normal
  • Type set to New feature

comment:3 Changed 3 years ago by aaugustin

  • UI/UX unset

Change UI/UX from NULL to False.

comment:4 Changed 3 years ago by aaugustin

  • Easy pickings unset

Change Easy pickings from NULL to False.

comment:5 Changed 2 years ago by akaariai

  • Resolution set to wontfix
  • Status changed from new to closed

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