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 698751
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T03:18:38+00:00 2026-05-14T03:18:38+00:00

I am building an app to learn Django and have started with a Contact

  • 0

I am building an app to learn Django and have started with a Contact system that currently stores Contacts and Addresses. C’s are a many to many relationship with A’s, but rather than use Django’s models.ManyToManyField() I’ve created my own link-table providing additional information about the link, such as what the address type is to the that contact (home, work etc). What I’m trying to do is pass this information out to a view, so in my full view of a contact I can do this:

def contact_view_full(request, contact_id):
    c = get_object_or_404(Contact, id=contact_id)

    a = []
    links = ContactAddressLink.objects.filter(ContactID=c.id)    
    for link in links:
        b = Address.objects.get(id=link.AddressID_id)
        a.append(b)

    return render_to_response('contact_full.html', {'contact_item': c, 'addresses' : a }, context_instance=RequestContext(request))

And so I can do the equivalent of c.Addresses.all() or however the ManyToManyField works. What I’m interested to know is how can I pass out information about the link in the link object with the 'addresses' : a information, so that when my template does this:

{% for address in addresses %}
<!-- ... -->
{% endfor %}

and properly associate the correct link object data with the address.

So what’s the best way to achieve this? I’m thinking a union of two objects might be an idea but I haven’t enough experience with Django to know if that’s considered the best way of doing it. Suggestions?

Thanks in advance.

Nf

  • 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-14T03:18:38+00:00Added an answer on May 14, 2026 at 3:18 am

    In order to add extra information, you should use a ManyToMany relationship with a ‘trough’ extra-field :
    http://docs.djangoproject.com/en/dev/topics/db/models/#extra-fields-on-many-to-many-relationships

    This will lead to this code:

    def contact_view_full(request, contact_id):
        c = get_object_or_404(Contact, id=contact_id)
        a = c.addresses.all()
        return render_to_response('contact_full.html', {'contact_item': c, 'addresses' : a }, context_instance=RequestContext(request))
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I finished building an app that allows beaming of photos, contacts and text clips
To learn ASP.net I started building a todo web app(web forms not MVC), this
i just started building a small test app to help me learn MVC. i
I'a currently building an app for android that users connect to it by UserName
I'm building an app to learn Rails, and I'm not sure how to go
I am building an app and want to have a lot of the site
I am building an app that plays multiple video files, But I would like
I'm trying to learn Make and building a Makefile into my app to help
I am currently building an Adobe Air desktop app for a medium sized company
I am building a web application that have several requirements for the client: 1.

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.