I like it, always wondered if there was a way to do this in the core. Hope the patch gets through.
J. Leclanche / Adys On Fri, Dec 25, 2009 at 1:22 AM, Michael P. Jung <mpj...@terreon.de> wrote: > On 2009-12-24 19:45, Stephen Crosby wrote: > > In your address example, I'm not sure what advantage this > > CompositeField has over just creating an address model/table and > > using a regular foreign key to reference it. You mentioned the need > > to create a field composed of other fields which to me sounds a lot > > like a regular one-to-many relationship between two normalized > > tables. Can you explain the reasons you decided to do it this way and > > the advantages you see? > > Actually the whole idea of this is to store the data denormalized. I > have to agree that the given example makes little to no sense, as it is > lacking a sane context. In one of our applications the AddressField is > used in several models, but the stored addresses are never shared, thus > normalizing them brings no benefit. Contrary, a separate table would > cause more complex and slower queries. > > I agree that a 1-to-N relationship, with N being some rather low > constant number, shouldn't be realized that way, but I find it quite > practical for true 1-to-1 relationships. > > > Better and less synthetic examples for composed fields would be: > > class Length(CompositeField): > value = models.DecimalField(...) > unit = models.CharField(choices=UNIT_CHOICES) > > class Location(CompositeField): > longitude = models.FloatField() > latitude = models.FloatField() > altitude = models.FloatField() > > class FullNameField(CompositeField): > prefix = models.CharField(max_lenght=20, blank=True) > first = models.CharField(max_lenght=20) > middle = models.CharField(max_lenght=20, blank=True) > last = models.CharField(max_lenght=20) > suffix = models.CharField(max_lenght=20, blank=True) > > class PhoneNumber(CompositeField): > country = models.CharField(max_lenght=4, blank=True) > area = models.CharField(max_lenght=8, blank=True) > subscriber = models.CharField(max_lenght=16) > > > I hope all that makes a bit more sense now? > > > --mp > > -- > > You received this message because you are subscribed to the Google Groups > "Django developers" group. > To post to this group, send email to django-develop...@googlegroups.com. > To unsubscribe from this group, send email to > django-developers+unsubscr...@googlegroups.com<django-developers%2bunsubscr...@googlegroups.com> > . > For more options, visit this group at > http://groups.google.com/group/django-developers?hl=en. > > > -- You received this message because you are subscribed to the Google Groups "Django developers" group. To post to this group, send email to django-develop...@googlegroups.com. To unsubscribe from this group, send email to django-developers+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-developers?hl=en.