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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T13:20:09+00:00 2026-05-30T13:20:09+00:00

I have a problem with an Error I dont quite understand.. when i execute

  • 0

I have a problem with an Error I dont quite understand..
when i execute the code below, i get the following Message:

ValueError: Cannot assign "[<Location: somename>]": "Event.location" must be a "Location" instance.

It clearly states that “somename” is of the type Location, but complains that its the wrong type.. what should I do? Unfortunately the interpreter doesnt give me to many hints 🙁

    if location is not None:
        location = location.group(1)
        l=Location.objects.filter(name=location)
        if not l:
            l = Location(name=location)
            l.save()

    if price is not None:
        price = price.group(1)

    if starttime is not None:
        starttime = extract_time_from_string(starttime.group(1))

    if name is not None:
        name = name.group(1)

    if edate is not None and name is not None and l is not None:
        if not Event.objects.filter(name = name, eventdate=edate,
                location = l):
            e= Event(location = l, name = name,
                    eventdate=edate, starttime=starttime,
                    price=price)
  • 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-30T13:20:10+00:00Added an answer on May 30, 2026 at 1:20 pm
    ValueError: Cannot assign "[<Location: somename>]": "Event.location" must be a "Location" instance.
    

    When it says that [<Location: somename>] was passed, the brackets means it’s a list.

    The problem is that the l variable can have different types in your code.

    Here it is a QuerySet (list-compatible type) of Location:

    l=Location.objects.filter(name=location)
    

    Here it is a location:

    l = Location(name=location)
    

    You should ensure that l contains a location in both cases, for example, with this else block:

        l=Location.objects.filter(name=location)
        if not l:
            l = Location(name=location)
            l.save()
        else:
            l = l[0]
    

    As you’re trying to get one location instance, you might as well use get() instead of filter():

    try:
        l = Location.objects.get(name=location)
    except Location.DoesNotExist:
        l = Location(name=location)
        l.save()
    

    That’s basically what does the get_or_create() method:

    l, created = Location.objects.get_or_create(name=location)
    

    A common pitfall you have to watch out for when using get_or_create(), is that it returns 2 values. The first being the model, the second being a boolean which is True if the object was created, and False if it was found.

    Documentation for get_or_create: https://docs.djangoproject.com/en/dev/ref/models/querysets/#get-or-create

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

Sidebar

Related Questions

Greetings, I have problem with errorPlacement, I'm trying to place the error message next
I'm battling an error I don't quite understand. I have a class in Java,
I have a problem with a javascript error: $(#slider) is undefined How can i
I have a problem where a method is getting an undefined variable error, even
Ok so I have a recursion problem thats causing a stack overflow error at
I have problem compilin this code..can anyone tell whats wrong with the syntax CREATE
I have following code on my site: backgroundImages[bg_img_path_b]=new Image(); backgroundImages[bg_img_path_b].src = bg_img_path_b; backgroundImages[bg_img_path_b].loaded=loading; //jQuery(backgroundImages[lastImage]).unbind('load.backgroundImages');
I have an interesting problem, however I don't know quite how to articulate it
I have a quite difficult problem with binary files. I have been asked to
_ I had problem with installing the mod_wsgi.I have found the solution as below

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.