Thursday, December 29, 2011

Re: Constraints on a one-to-many relationship and related problems

At 2011-12-28 06:21:38 -0800, Dan Gentry wrote:
> Just looking at the models, I'd like to make a couple of suggestions.
>
> Instead of using a Foreign Key relationship in Customer to indicate
> the billing address, I would include a flag called 'billing_address'
> in the Address table that would be set to True for the customer
> selected address.
>
> An override of save() in the Address model is then used to enforce the
> 'only one billing address' rule.

This certainly simplifies things, but there are still a couple of
problems.

Firstly, the user gets no warning if he checks multiple "is billing
address" boxes on the inline forms and it doesn't seem to be totally
predictable which of the addresses' save methods will be called, and
then which will be called last, and therefore which will end up being
marked as the billing address. Any suggestions? Or is there a way to
make them show up as radio buttons?

Next, there's nothing to stop no addresses being given, or no
addresses being marked as the billing address. I guess I could put the
monkey patch back on so I can force the first address to be billing if
none is. Is that the best solution to this problem? But even then the
problem of how to stop a customer being created if no addresses are
given remains.

Thanks.

--bart

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to django-users+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/django-users?hl=en.

No comments:

Post a Comment