Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3444914
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T08:58:32+00:00 2026-05-18T08:58:32+00:00

I have model Person or say Profile and this class Person has a genericRelationship

  • 0

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

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-18T08:58:33+00:00Added an answer on May 18, 2026 at 8:58 am

    As per Django Doc

    Generic Relations : let an object have
    a foreign key to any object through a
    content-type/object-id field. A
    GenericForeignKey field can point to
    any object, be it animal, vegetable,
    or mineral.

    This means you can do what you are saying you want to do.

    UPDATE: Adding some code. This would be your forms.py

    class EditForm(forms.Form):                              
        title     = forms.CharField(label='Username', max_length=30)
        phone_num1= forms.CharField(label='Phone Number1',widget=forms.TextInput())
        phone_num2= forms.CharField(label='Phone Number2',widget=forms.TextInput())  
    

    This 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. in views.py.

    if request.GET.has_key('edit'): # already there - EDIT
        nameid = request.GET['edit']
        try:
            person   = Person.objects.get(id=nameid)
            phonenum = PhoneNumber.objects.get(user=request.user, person=person)
            pnums    = ' '.join(n.phone_number for n in person.phonenum_set.all())
        except (PhoneNumber.DoesNotExist, Person.DoesNotExist):
            raise
        form = EditForm({'title:person.title, 'phonunumbers': phonenums})
    

    This is the general idea. There might be some syntax errror as I am typing this in the browser…

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Say I have a model object 'Person' defined, which has a field called 'Name'.
Say I have a Django class something like this: class Person(models.Model): name = models.CharField(max_length=50)
Lets say I have a set of model classes like this: public class Person
Say I have some django models, something like this: class Address(models.Model): pass class Person(models.Model):
I have a model in my rails application which is class Person < ActiveRecord::Base
Say I have the following model: class Person(models.Model): street_address = models.CharField(max_length=50, blank=True) suburb =
I have a model object in my controller. let's say Class person{ Date birthDay;
Say I have the good old person/group/membership relationship class Person(models.Model): name = models.CharField(max_length=128) def
Let's say I have Person EMF Model. I create 2 instances of this model
I have a model called Person. I want User to inherit from Person. class

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.