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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T14:49:46+00:00 2026-06-12T14:49:46+00:00

I have been struggling to see what is wrong with this code for couple

  • 0

I have been struggling to see what is wrong with this code for couple hours now. The project i m working on calls for users to register to the sites (taken care of by Django registration plugin.) Once registered, users will be able to add their company (name, address, phone etc…) to the site as a listing. So company has its own model. I am using Django profiles to show user info and company info on Django profiles page. Profiles also built on top of Django Profiles plugin.

url(r'^accounts/', include('registration.urls')),    
url(r'^admin_export/', include("admin_export.urls")),   
url(r'^profiles/edit', 'profiles.views.edit_profile'),
url(r'^profiles/create', 'profiles.views.create_profile'),
url(r'^profiles/', include('profiles.urls')),
url(r'^profiles/(?P<username>\w+)/$', 'profiles.views.profile_detail',name='UserProfileView'),
url(r'^comments/', include('django.contrib.comments.urls'))


#models.py

class UserProfile(models.Model):
    user = models.ForeignKey(User,unique=True)
    #email = models.CharField(max_length=200, blank=True, null=True)
    # Other fields here
    #company = models.ForeignKey(Company,blank=True,null=True)    
    #office = models.CharField(max_length=200, blank=True, null=True)    
    def __unicode__(self):
        return self.user.username




class Company(models.Model):
    userprofile = models.ForeignKey(UserProfile, null=True, blank=True)
    comp_name = models.CharField(max_length=200,blank=True,null=True)
    comp_address = models.CharField(max_length=200,blank=True, null=True)
    comp_email = models.CharField(max_length=200,blank=True, null=True)
    comp_zip = models.IntegerField(blank=True, null=True)
    comp_phone = models.IntegerField(blank=True, null=True)
    comp_city = models.CharField(max_length=200,blank=True, null=True)
    #comp_state = models.USStateField(blank=True, null=True
    comp_state = models.CharField(blank=True, max_length=2)
    compwebsite = models.URLField(max_length=200, blank=True, null=True)
    twitterurl = models.URLField(max_length=200, blank=True, null=True)
    facebookurl = models.URLField(max_length=200, blank=True, null=True)
    def __unicode__(self):
        return self.comp_name

class ProfileForm(ModelForm):
    class Meta:
        model=UserProfile
        exclude=('user',)

#views.py
def UserProfileView(request, username):
    context_dict = {}
    usercompany =  get_object_or_404(Company, user=userprofile)
    context_dict = {'usercompany': usercompany}
    return render_to_response('profile_detail.html', context_dict, RequestContext(request))
  • 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-06-12T14:49:48+00:00Added an answer on June 12, 2026 at 2:49 pm

    userprofile is actually not available when it’s referenced in your views.py, so it should raise NameError

    If I understood you right, the way to achieve this is:

    #views.py
    def UserProfileView(request):
        context_dict = {}
        usercompany =  get_object_or_404(Company, userprofile__user=request.user)
        context_dict = {'usercompany': usercompany}
        return render_to_response('profile_detail.html', context_dict, RequestContext(request))
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have been struggling with this for a while now. given a set of
I have been struggling with this error for more than two hours: error: aggregate
I have been struggling with this question for awhile now, and I haven't reached
I have been struggling with a problem for a couple of days now with
I have been struggling with this a while now. I implemented a basic IHttpHandler
sorry to post this but have been struggling now for 8 days and really
I have been struggling with this issue for the past couple days: I have
I have been struggling with this problem for a few days now and I
I've been struggling with this for a while now, and I see that I'm
I have been struggling with this for a while now so I thought I

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.