I have model Person or say Profile and this class Person has a genericRelationship with the phonenumber class.Now I wanted to generate a ModelForm which displays the option of adding two or three contact numbers at a time in a single form. Is this possible ?
My models look like :
class Person(models.Model):
"""Person model"""
title = models.CharField(_('title'), max_length=20, null=True, blank=True)
first_name = models.CharField(_('first name'), max_length=100)
middle_name = models.CharField(_('middle name'), max_length=100, null=True,
blank=True)
last_name = models.CharField(_('last name'), max_length=100, null=True,
blank=True)
suffix = models.CharField(_('suffix'), max_length=20, null=True,
blank=True)
slug = models.SlugField(_('slug'), max_length=50, unique=True)
phone_number = generic.GenericRelation('PhoneNumber')
email_address = generic.GenericRelation('EmailAddress')
address = generic.GenericRelation('Address')
date_of_birth = models.DateField(_('date of birth'), null=True, blank=True) gender = models.CharField(_('gender'), max_length=1, null=True,
blank=True, choices=GENDER_CHOICES)
class PhoneNumber(models.Model):
"""Phone Number model."""
PHONE_LOCATION_CHOICES = (
('w', _('Work')), 315 ('m', _('Mobile')),
('f', _('Fax')),
('p', _('Pager')),
('h', _('Home')),
('o', _('Other')),
)
content_type = models.ForeignKey(ContentType, limit_choices_to{'app_label': 'contacts'})
object_id = models.IntegerField(db_index=True)
content_object = generic.GenericForeignKey()
phone_number = models.CharField(_('number'), max_length=50)
location = models.CharField(_('location'), max_length=1,
choices=PHONE_LOCATION_CHOICES, default='w')
date_added = models.DateTimeField(_('date added'), auto_now_add=True)
date_modified = models.DateTimeField(_('date modified'), auto_now=True)
Then I wanted to make a form for editing the contacxt details.
I would be very thankful to yoy!
Thank You!
Regards
As per Django Doc
This means you can do what you are saying you want to do.
UPDATE: Adding some code. This would be your
forms.pyThis could be your
views.py. In your HTML code provide an EDIT link, which has the url in some format. This url format should be mapped in your urls.py file. Which would invoke this fn. inviews.py.This is the general idea. There might be some syntax errror as I am typing this in the browser…