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

  • Home
  • SEARCH
  • 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

Here is the issue I am having: I have a large query that needs
Here's my issue: I need to close a process, already running, from a C#
Here's the issue: I have a hook in IE that reacts on WebBrowser.OnNavigateComplete2 event
Here is my issue. I have an array containing the name of cities that
I have a similar issue like here: http://social.msdn.microsoft.com/forums/en-US/biztalkgeneral/thread/87d5a6ec-04ee-4c6f-8267-f526ee105f0b I have an asp.net web page
I just moved a django project to a deployment server from my dev server,
Here's my issue, I'd like to mock a class that creates a thread at
Alright so here is my issue. I'm working a game engine that will eventually
Obviously I can use BCP but here is the issue. If one of the
Here's the quick and skinny of my issue: $(a).toggle(function() { /*function A*/ }, function()

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.