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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T20:09:30+00:00 2026-05-17T20:09:30+00:00

Here is my issue. I am new to python/django (about 2 months in). I

  • 0

Here is my issue. I am new to python/django (about 2 months in). I have 2 tables, Project and Status. I have a foreign key pointing from status to project, and I am looking to try to display the value of the foreign key (status) on my project template, instead of the address of the foreign key.

Here is my models.py

from django.db import models
from clients.models import Clients
from django.contrib.auth.models import User
from settings import STATUS_CHOICES

from django.db import models
from clients.models import Clients
from django.contrib.auth.models import User
from settings import STATUS_CHOICES

class Project(models.Model):
   client = models.ForeignKey(Clients, related_name='projects')
   created_by = models.ForeignKey(User, related_name='created_by')


#general information
   proj_name = models.CharField(max_length=255, verbose_name='Project Name')
   pre_quote = models.CharField(max_length=3,default='10-')
   quote = models.IntegerField(max_length=10, verbose_name='Quote #', unique=True)
   desc = models.TextField(verbose_name='Description')
   starts_on = models.DateField(verbose_name='Start Date')
   completed_on = models.DateField(verbose_name='Finished On')

   def __unicode__(self):
      return u'%s' % (self.proj_name)   


class Status(models.Model):
  project = models.ForeignKey(Project, related_name='status')
  value = models.CharField(max_length=20, choices=STATUS_CHOICES,                     verbose_name='Status')
  date_created= models.DateTimeField(auto_now=True) 

  def __unicode__(self):
     return self.value

  class Meta:
      verbose_name = ('Status')
      verbose_name_plural = ("Status")

My views.py

@login_required
 def addProject(request):
 if request.method == 'POST':
      form = AddSingleProjectForm(request.POST)
      if form.is_valid():
        project = form.save(commit=False)
        project.created_by = request.user  
        project.save()
        project.status.create(
                value = form.cleaned_data.get('status', None)
        )            
        return HttpResponseRedirect('/project/')
 else:
    form = AddSingleProjectForm()

 return render_to_response('project/addProject.html', {
 'form': form, 'user':request.user}, context_instance=RequestContext(request))

And finally my template:

{% if project_list %}
<table id="plist">
    <tr id="plist">
        <th>Quote #</th>
        <th>Customer</th>
        <th>Date</th>
        <th>Project Name</th>
        <th>Status</th>
        <th>Contact</th>
    </tr id="plist">
    {% for p in project_list %}
    <tr id="plist">
        <td><a href="/project/{{ p.id }}/view">{{ p.pre_quote }}{{ p.quote }}</a></td>
        <td>{{ p.client }}</td>
        <td>{{ p.starts_on }}</td>
        <td>{{ p.proj_name }}</td>
        <td>{{ p.status_set.select_related }}</td>
    <td>{{ p.created_by }}</td>
    </tr>
     {% endfor %}
    </table>

{% else %}
    <p>No projects available.</p>
{% endif %}

Any help would be much appreciated. Thank you!

  • 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-17T20:09:31+00:00Added an answer on May 17, 2026 at 8:09 pm

    I’m guessing you mean here:

    <td>{{ p.status_set.select_related }}</td>
    

    This doesn’t do anything. select_related is an optimisation feature, it has nothing to do with actually getting or displaying the related content. If you want to do that, you will have to iterate through the result of p.status_set.all.

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

Sidebar

Related Questions

I have a curious issue here In my ejbCreate() method from where i insert
Disclaimer: I am new to python and django but have Drupal programming experience. I'm
Having an issue here that I have tried everything I can think of but
I have a rather annoying issue here I can't get my CheckBox CheckedChange event
I'm having an issue here, I am trying to get all the titles from
Hey guys I have a little issue here. I have a panel where I
I just moved a django project to a deployment server from my dev server,
im new with mongo and so far have no issue using it. Until i
I learned about multiprocessing from Python and I'm having a bit of trouble understanding
Caveat: new to Python. Wanting to hear from professionals who actually use it: What

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.