Opened 16 years ago

Closed 16 years ago

#9197 closed (wontfix)

Add new fieldtype (eg. Extra)

Reported by: anonymous Owned by: nobody
Component: Database layer (models, ORM) Version: 1.0
Severity: Keywords:
Cc: Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

If I need often call QuerySets' .extra it is more convinient to add new field type Extra. Ie if I'd like to compute ABS value then instead of

Model.object.extra(select={'abs_value':'ABS(value)'})

every time it would be nice to add to Model new attribute,something like this:

  abs_value = model.Extra('ABS(value)')

Change History (1)

comment:1 by Malcolm Tredinnick, 16 years ago

Resolution: wontfix
Status: newclosed

You can already write custom field types that end up producing pretty much whatever SQL you like (this is how GeoDjango does a lot of stuff, for example). Writing custom field classes is documented.

This doesn't sound like a particularly robust way to do something in Django's core, since it's adding something that looks like a model field, but isn't really (since setting the attribute value does nothing for example). I think this is best done as a third-party field object if that's the way you want to work, rather than including it in core. It looks a bit too confusing and we already have custom managers and extra() to do this right now.

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