I've written something called a 'CompositeField' which basicly does what
you're looking for by grouping fields together. Assume you want to have
an AddressField you could define it the following way:
class AddressField(CompositeField):
def __init__(self, blank=False):
super(AddressField, self).__init__(
addressee=models.CharField(max_length=30, blank=blank),
street=models.CharField(max_lenghth=40, blank=blank),
zipcode=models.CharField(max_length=5, blank=blank),
city=models.CharField(max_lenght=30, blank=blank),
)
Using it is equally simple:
class Customer(models.Model):
billing_address = AddressField()
shipping_address = AddressField(blank=True)
It will create extra fields in the model called
billing_address_addressee, billing_address_street, etc. and also provide
some helpers which makes assignment simple. e.g. foo.shipping_address =
foo.billing_address will work as expected.
The code is almost ready for prime. I just want to include some minor
change and add some more test cases. It is ment to be licensed under BSD
just like Django itself. I'd be delighted to get that code included into
Django core some day.
Would this be of any help to you?
--mp
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Django developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/django-developers?hl=en
-~----------~----~----~----~------~----~------~--~---