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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T00:24:54+00:00 2026-05-22T00:24:54+00:00

I am trying to hardcode the following in my view for testing purposes. How

  • 0

I am trying to hardcode the following in my view for testing purposes. How do I do this without encountering an error?

My view:

`def create(request):
form= PlayForm(request.POST or None)
if form.is_valid():

    play = form.save(commit=False)
    play.track = 2
    play.save()
    request.user.message_set.create(message='Play Was created')
    if 'next' in request.POST:
        next = request.POST['next']
    else:
        next = reverse('coup_show')
    return HttpResponseRedirect(next)
return render_to_response(
    'dash/create.html',
    {'form':form},
    context_instance = RequestContext(request)`

My model:

class Play(models.Model):
    track = models.ForeignKey(Track,null=True, related_name='track_creator_set')

When I try this I get the following error…

Cannot assign "2": "Play.track" must be a "Track" instance.
  • 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-22T00:24:55+00:00Added an answer on May 22, 2026 at 12:24 am

    Try this:

    play.track = Track.objects.get(pk=2)
    

    You need to assign an instance of the Track model, rather than just the pk.

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

Sidebar

Related Questions

I'm trying to manually build form fields for a testing purpose. I got the
I'm trying to accomplish the following content in source code: <div id=box<%=id%>></div> Without escaping
When trying to execute the following: def postToMySQL(date,data,date_column_name,data_column_name,table): cursor = conn.cursor () sql =
I keep getting the following error when trying to run an application in the
I'm trying to hardcode a function as string, turn it into a function and
Trying to make this jQuery filter that uses .find case-insensitive. For example, when the
Trying to figure out how I can do this properly. The print_r looks like
Trying to copy the msdn refernce here doesn't work and gives an error I
trying to figure out why this is happening - I have an input text
I am new to ASP.NET MVC. I am trying to create what I thought

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.