Maybe I'm missing something, but I don't understand how is this
different from having a bunch of separate fields. The CompositeField
adds a namespace, but foo.bar_x=1 seems to be no harder to read than
foo.bar.x=1. I must admit that this field solves another problem well:
it makes easier to copy sets of fields. However, if this is done
frequently, the chances are high that denormalization is what we
actually need. So I think this field may be great in some use cases,
but in most cases it would rather overcomplicate things. Feel free to
ignore this comment if I'm missing the point :)

Andy

On 25 дек, 04:22, "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.
For more options, visit this group at 
http://groups.google.com/group/django-developers?hl=en.


Reply via email to