Django

Code

Ticket #5929 (new)

Opened 6 months ago

Last modified 6 months ago

Allow Fields to use multiple db columns (complex datatypes)

Reported by: poelzi Assigned to: nobody
Component: Database wrapper Version: SVN
Keywords: Cc:
Triage Stage: Accepted Has patch: 0
Needs documentation: 0 Needs tests: 0
Patch needs improvement: 0

Description

Currently it seems that it is not possible to have complex db filds. For example: Implementation of a IP model which actually should be a field type not a model. The implementation is not clean, because foreign key lookups for example do not work. The model maps for example:

NetworkAddress.objects.filter(ip__in="192.168.0.10/16")

into a complex query for a ip resisting in a network range.

Due the fact that model fields can only map to one db column, many complex data types can't be implemented. For example a ipv6 ip address which is a 128 bit value can't be handled by most db implementations of integer fields, so it has to be expanded to multiple columns plus a additional netmask column. Using varchar doesn't work because there is no way to search for network ranges or IPs in ranges, etc... I think a field should be able to implement lookup mappings which can be overridden to implement complex datatypes as well as use multiple db fields.

Attachments

Change History

11/12/07 21:54:38 changed by Jim Meier <jim-django@dsdd.org>

  • needs_better_patch changed.
  • needs_tests changed.
  • needs_docs changed.

The relational db literature seems to teach me that related tables (and so related models) would seem to already be the standard way to handle complex data types. Why do you say that this IP model should be a field type rather than a model?

11/13/07 08:50:12 changed by poelzi

  • stage changed from Unreviewed to Design decision needed.

Let's see another example: http://django-coordinatesfield.googlecode.com/svn/trunk/field.py

This Field is implemented as a Charfield which is actually not the right datatype. The right datatype would be 2 or 3 float or decimal values or a real geos point value.

First thing: I'm not sure if it is currently possible to fix the IP Model, but currently the lookups only work if you filter trough the NetworkAddress? model itself, because it uses a special manager to rewrite the simplified lookup methods into real ones. Becaus this is manager specific, there is no way to make lookups through the normal ForeignKey? interface. So every lookups is specific for this model. Not good.

The NetworkAddress? Model is quite complex, because it implements some other required tools. But actually, the system uses ForeignKey? relations to this model that really only represents a simple IP without all the blow, but blowing this table into a really hugh one. This is another point: performance. If you have some models with only a view records that has to be fast, and some with really many entries, lets say millions and you have lookups to the ip field queries are much slower than real implementations.

For me this is a point of clarity. A field implements a type of data, which will be implemented in one way or the other depending on the database backend used. Thats the sense of having a abstraction layer, and if most or non of the databases don't have a type that fits, it's still one field for me, even when the implementation of field uses more then one db field to implement a the functionality as it should. A model represents for me a more or less independent peace of informations that could be referred to, but is not essentially coupled to. It's just, that i don't feel like that it's right designed right in such cases :-)

11/28/07 16:18:08 changed by mtredinnick

  • keywords deleted.

Removing the qs-rf keyword, since this is out of scope for the SQL construction rewrite. It's something we can look at after that is completed, though.

11/30/07 15:09:21 changed by jacob

  • version changed from other branch to SVN.

11/30/07 15:11:07 changed by jacob

  • stage changed from Design decision needed to Accepted.

Add/Change #5929 (Allow Fields to use multiple db columns (complex datatypes))




Change Properties
Action