Monday, April 30, 2012

How to create form from odd model

Hi,
I am working with an existing database where I am unable to change the
schema and having some trouble trying to deal with presenting forms.
The structure in question is as follows and all models are unmanaged.

class Persons(models.Model):
personid = models.BigIntegerField(primary_key=True,
db_column='PersonID')
....

class Phones(models.Model):
phoneid = models.BigIntegerField(primary_key=True,
db_column='PhoneID')
number = models.CharField(max_length=60, db_column='Number',
blank=True)
type = models.CharField(max_length=15, db_column='Type',
blank=True)
...

class Personsphones(models.Model):
personphoneid = models.BigIntegerField(primary_key=True,
db_column='PersonPhoneID')
personid = models.ForeignKey(Persons, db_column='PersonID')
phoneid = models.ForeignKey(Phones, db_column='PhoneID')
...

I want to create a form to display all of the 'Phones' associated with
a particular 'Persons' and in addition be able to modify/add/remove
'Phones' belonging to a 'Persons'. Right now the only thing I can
think of is to display the 'Phones' in a modelformset and then if one
is added or removed manually set the 'Personsphones' relation. Any
ideas on how to best deal with this model setup? If I manually need to
update the relationships should I just create a custom save() for my
'Phones' form?

--
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