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

The Archive Base Latest Questions

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

I’m using Django 1.4 with Python 2.7 on Ubuntu 12.04. Edit: I’m clearing some

  • 0

I’m using Django 1.4 with Python 2.7 on Ubuntu 12.04.

Edit: I’m clearing some of the erroneous portions of this question out as it appears the same problem has re-occurred. It was working wonderfully – I made no changes – and now it’s failing. What’s up with that?

This is basically what the views look like:

@login_required
def request_new_project(request):
    """
    ..  function:: request_new_project()

        Collect information to call the form used to create a new project

        :param request: Django Request object
    """
    user_dict = { 'rsb_username'  : request.user.username}
    form = CreateProject(initial = user_dict)
    data = { 'user' : request.user }
    data.update(csrf(request))
    data.update({ 'form' : form })

    return render_to_response("create_project.html", data)

@login_required
def add_project(request):
    """
    ..  function:: add_project()

        Add a project for the user

        :param request: Django Request object
    """

    if (request.method == "POST"):
        user = User.objects.get(username = request.POST.get('rsb_username'))
        userProfile = UserProfile.objects.get(user = user)

        new_project = Projects(client = userProfile,
                               project_name = request.POST.get('rsb_project_name'),
                               description = request.POST.get('rsb_description'),
                               budget = request.POST.get('rsb_budget'),
                               time_frame = request.POST.get('rsb_time_frame'),
                               time_frame_units = request.POST.get('rsb_time_frame_units'),
                               contact = request.POST.get('rsb_point_of_contact'),
                               contact_email = request.POST.get('rsb_contact_email'),
                               contact_phone = request.POST.get('rsb_contact_phone'),
                               price_quote = 0,
                               eta = 'To Be Determined',
                               current_status = 'Waiting for quote',
                               )
        new_project.save()
        return view_projects(request)

I get the following error:

Cannot assign "<UserProfile: UserProfile object>": "Projects.client" must be a "User" instance.

I didn’t change the models.

# Create a table for users
class UserProfile(models.Model):
    user = models.OneToOneField(User)

    # Client Info
    company_name = models.CharField(max_length = 200)
    client_type = models.CharField(max_length = 200)
    address1 = models.CharField(max_length = 200)
    address2 = models.CharField(max_length = 200)
    city = models.CharField(max_length = 200)
    state = models.CharField(max_length = 200)
    country = models.CharField(max_length = 200)
    zip_code = models.CharField(max_length = 200)
    phone_number = models.CharField(max_length = 200)

# Create a table to manage project requests
class Projects(models.Model):
    client = models.ForeignKey(User)
    project_name = models.CharField(max_length = 50)
    description = models.TextField()
    budget = models.CharField(max_length = 50)
    time_frame = models.DecimalField(max_digits = 3, decimal_places = 1)
    time_frame_units = models.CharField(max_length = 25)
    contact = models.CharField(max_length = 50)
    contact_email = models.EmailField()
    contact_phone = models.CharField(max_length = 25)
    price_quote = models.DecimalField(max_digits = 10, decimal_places = 2)
    eta = models.CharField(max_length = 200)
    current_status = models.CharField(max_length = 200)

Any suggestions?

UPDATE 1:
From the actual database I can see that one of the rsb_projects constraints is:
rsb_projects_client_id_fkey (client_id) REFERENCE rsb_userprofile (id) MATCH SIMPLE ON UPDATE NO ACTION ON DELETE NO ACTION DEFERRABLE INITIALLY DEFERRED

If that helps…

It seems to me that even though I’ve defined the ForeignKey in the models.py to be against User the database wants the UserProfile id.

Thoughts?

  • 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-12T19:03:47+00:00Added an answer on June 12, 2026 at 7:03 pm

    The error is exactly what it says it is.

    In order to create the new project you need to give your project object a user profile object, not a user profile id.

       user = User.objects.get(id=7)
       userprofile = user.get_profile()
       project.client = userprofile
    

    Notice that it is userprofile object that is assigned to the project instance’s client attribute. You cannot assign the userprofile object’s id to the project instance’s client attribute.

    Also, do not confuse your user id with your userprofile id. They may not be exactly the same.

    The user id is the primary key auto-generated in the auth_user table whenever a new user is created in your database.
    The userprofile id is the primary key auto-generated in the profiles_userprofile table whenever a corresponding user profile is created that is related to a user.

    In other words, your add_project view function needs to read something like

    if (request.method == "POST"):
        user = User.objects.get(username = request.POST.get('rsb_username'))
        # userprofile = UserProfile.objects.get(user = user)  <-- we don't need this anymore.
    
        new_project = Projects(client = user,  # <--- give it a user instance of course now that your model has changed
                               project_name = request.POST.get('rsb_project_name'),
                               description = request.POST.get('rsb_description'),
                               budget = request.POST.get('rsb_budget'),
                               time_frame = request.POST.get('rsb_time_frame'),
                               time_frame_units = request.POST.get('rsb_time_frame_units'),
                               contact = request.POST.get('rsb_point_of_contact'),
                               contact_email = request.POST.get('rsb_contact_email'),
                               contact_phone = request.POST.get('rsb_contact_phone'),
                               )
        new_project.save()
    

    The key takeaway is that you need to be sure what your original model definition is.

    If in your Project class, your client attribute is assigned as FK to User, then you need to give it a user object.

    If in your Project class, your client attribute is assigned as FK to UserProfile, then you need to give it a userprofile object.

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

Sidebar

Related Questions

For some reason, after submitting a string like this Jack’s Spindle from a text
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
This could be a duplicate question, but I have no idea what search terms
I know there's a lot of other questions out there that deal with this
I'm new to using the Perl treebuilder module for HTML parsing and can't figure
That's pretty much it. I'm using Nokogiri to scrape a web page what has
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have just tried to save a simple *.rtf file with some websites and
I am reading a book about Javascript and jQuery and using one of the

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.