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

The Archive Base Latest Questions

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

Upon extending the excellent django project django-profiles (found on https://bitbucket.org/ubernostrum/django-profiles/wiki/Home ) I stumbled upon

  • 0

Upon extending the excellent django project django-profiles (found on https://bitbucket.org/ubernostrum/django-profiles/wiki/Home) I stumbled upon something which I have been trying to solve for days.

The idea is fairly simple. I have users, which have user profiles (object UserProfile, linked to User). Now I added a new object to my project, Employment, which also links to the User object.

class Employment(models.Model):
    """
    A class to describe the relationship of employment, past or present, between an employee and an organization.

    """

    def __unicode__(self):
        return self.function

    def get_absolute_url(self):
        return "/recycling/employment/%i/" % self.id

    user = models.ForeignKey(User)
    organization = models.ForeignKey(Organization)
    date_start = models.DateField('Start date of employment', help_text="Please use the following format: YYYY-MM-DD.", null=True, blank=True)
    date_end = models.DateField('End date of employment', help_text="Please use the following format: YYYY-MM-DD.", null=True, blank=True)
    function = models.CharField(max_length=100)
    present_job = models.BooleanField()


class UserProfile(models.Model):
    """
    A class representing a the profile of a user.  Needs to be generic enough to involve both employees as employers.

    """

    def _get_absolute_url(self):
        return ('profiles_profile_detail', (), { 'username': self.user.username })

    # Link person to user
    user = models.ForeignKey(User, unique=True, null=True)

    registration_date = models.DateField(auto_now_add=True)

Now I would like to have a page (detail view) where I can show the UserProfile and also all employment for a specific user.
I figured that adding extra_context is the way to go and this works eg.:

('^profiles/(?P<username>\w+)/$', 'profiles.views.profile_detail', {'extra_context': {'employment_list': Employment.objects.all(),}}), 

The problem I am facing however is that I would like to have user-specific objects (thus filtering) and not just all().
One pitfall is that the django-profiles project still works with functions as views, not classes, so subclassing is not an option. Another attention point is that the view should not be cached, so that if a user adds another employment object and is redirected to the details page, this change should be reflected.
It would be nice to find a solution for this without adapting the django-profiles code itself…

Thanks for your help!


Found a way of doing this, turned out to be fairly simple. I created a new view which generates a list with a filter. Pass this list in extra_context to the view defined in the profiles application and done…

def detail_userprofile_view(request, username):
    """
    Returns a detail view including both the User Profile and the Employments linked to the user.
    """

    employment_list = Employment.objects.filter(user__username=username)
    context_dict = { 'employment_list': employment_list,}

    return profile_detail(request, username, extra_context=context_dict)
  • 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-23T20:17:18+00:00Added an answer on May 23, 2026 at 8:17 pm

    You could always write a new view. Something simple like:

    urls

    url(r'^profiles/(?P<username>\w+)/$', profiles.views.profile_detail, name='profile_detail'),
    

    views

    def profile_detail(request, username):
        context_dict = {}
        user = get_object_or_404(User, username=username)
        profile = get_object_or_404(Profile, user=user)
        employment = get_object_or_404(Employment, user=user)
    
        context_dict = { 'user': user,
                         'profile':profile,
                         'employment':employment,
        }
        return render_to_response('details.html', context_dict, RequestContext(request))
    

    Now in your template you can go {{ user.first_name }} or {{ profile }} or {{ employment.organization }} etc…

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

Sidebar

Related Questions

I just stumbled upon MainSoft's Grasshopper , which claims to cross-compile .Net ILM to
I'm about to embark upon extending and modifying PyUnit. For instance, I will add
I have just stumbled upon Bad Behavior - a plugin for PHP that promises
I stumbled upon an interesting error that I've never seen before, and can't explain
I have stumbled upon a bug in Safari on iPad. $('#next_proj a').trigger('click'); .. does
Expanding upon my earlier problem , I've decided to (de)serialize my config file class
Upon page load I want to move the cursor to a particular field. No
Upon a click on an IMG, I would like to get to the next
Upon AD Import for SharePoint, MOSS does this automatically: Office SharePoint Server 2007 automatically
Once upon a time I read how you detect programmatically for mounted NTFS folders

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.