I have accounts that can have multiple aliases, but each account must
have a primary alias.  I can think of two ways to institute this, but
they both have problems:

1) reference the primary alias from the account:

class Account(models.Model):
  ...
  primary_alias = models.OneToOneField('Alias',
related_name='accout_if_primary')

class Alias(models.Model):
  name = models.CharField(max_length=50, primary_key=True)
  account = models.ForeignKey(Account)

The trouble with this approach is that basically you can't create an
account without an alias, and you can't create an alias without an
account because of what amount to circular references, so you
essentially can't add any data.

2) Assign primary status to the alias:

class Account(models.Model):
  ...

class Alias(models.Model):
  name = models.CharField(max_length=50, primary_key=True)
  account = models.ForeignKey(Account)
  is_primary = models.BooleanField(default=False)

The trouble here is that it is a real pain to enforce that each
account has a primary alias (in fact you have to initially create an
account with no aliases and then create aliases and add them to it).
Additionally, enforcing a limit on the number of aliases is
problematic.  Finally, even if you do enforce these constraints
programmatically, it doesn't seem to be feasible to relay error
messages to contrib.admin.

Has anyone else encountered this design problem, and how did you go
about addressing it?

Thanks!


--~--~---------~--~----~------------~-------~--~----~
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+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to