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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T22:21:48+00:00 2026-06-04T22:21:48+00:00

I’m pretty new to python so it’s prolly a stupid mistake i made. I’m

  • 0

I’m pretty new to python so it’s prolly a stupid mistake i made.

I’m making an api which can be called using an external link. when calling the link my django server gives the following error: “‘RawQuerySet’ object has no attribute ‘key'”

Below is the code in which the error occures (definition of request, sql request and the model i use).
the error happens when i try to call planning.key. I believe django doesn’t know which type of object it is and doesn’t know how to retrieve data from it.

Hopefully somebody can see what i’m doing wrong.

code in which it’s going wrong

def get(request):
    if not len(request.GET):
        raise WeegNetError(101)

    data = request.GET.copy()

    usr = user.checkUser(data)

    planning = libs.getPlanning(data['planningkey'])

    if not planning:
        raise WeegNetError(310)

    fields = {
        'key': planning.key,
        'reference': planning.reference,
        'startdate': planning.plan_start.strftime("%Y-%m-%d %H:%M:%S"),
        'enddate': None if not p.plan_end else planning.plan_end.strftime("%Y-%m-%d %H:%M:%S"),
        'product': planning.product,
        'address_from': {
                                'relation': planning.rel_from,
                                'street': planning.street_from,
                                'housenr': planning.housenr_from,
                                'zipcode': planning.zipcode_from,
                                'city': planning.city_from
                        },
        'address_to': {
                                'relation': planning.rel_to,
                                'street': planning.street_from,
                                'housenr': planning.housenr_to,
                                'zipcode': planning.zipcode_to,
                                'city': planning.city_to
                        }}
    return HttpResponse(simplejson.dumps(fields))

sql request

def getPlanning(planningkey):
    sqlQuery = """SELECT k.key, 
        pl.id,
        pl.reference As ref, 
        pl.plan_start , 
        pl.plan_end, 
        pr.title as product,
        r1.name AS rel_from, 
        loc1.address AS street_from, 
        loc1.housenr AS housenrfrom, 
        loc1.zipcode AS zipcode_from, 
        loc1.city AS city_from, 
        r2.name as rel_to,  
        loc2.address AS street_to, 
        loc2.housenr AS housenr_to,
        loc2.zipcode AS zipcode_to, 
        loc2.city AS city_to 
        FROM `planning` pl
        LEFT JOIN `keys` k
        ON pl.id = k.planning_id
        LEFT JOIN `product` pr
        ON pl.product_id = pr.id
        LEFT JOIN `relations` r1
        ON pl.from_owner = r1.id
        LEFT JOIN `relations` r2
        ON pl.to_owner = r2.id
        LEFT JOIN `depot` dep1
        ON pl.to_depot = dep1.id
        LEFT JOIN `locatie` loc1
        ON dep1.locatie_id = loc1.id
        LEFT JOIN `depot` dep2
        ON pl.from_depot = dep2.id
        LEFT JOIN `locatie` loc2
        ON dep2.locatie_id = loc2.id
        WHERE pl.id = (SELECT planning_id
        FROM `keys`
        WHERE `key` = %(planningkey)s)
        AND pl.deleted = 0"""

    from models import Planning
    try:
        return Planning.objects.raw(sqlQuery, {'planningkey': planningkey})
    except:
        return None

model

class Planning(models.Model):
    id = models.AutoField(primary_key=True)
    key = models.CharField(max_length=8, blank=True, null=True)
    reference = models.CharField(max_length=255, blank=True, null=True)
    plan_start = models.DateField(null=False)
    plan_end = models.DateTimeField(null=True, default=None)
    product = models.CharField(max_length=255, blank=True, null=False)
    rel_from = models.CharField(max_length=255, blank=True, null=True)
    street_from = models.CharField(max_length=255, blank=True, null=True)
    housenr_from = models.CharField(max_length=10, blank=True, null=True)
    zipcode_fom = models.CharField(max_length=10, blank=True, null=True)
    city_from = models.CharField(max_length=255, blank=True, null=True)
    rel_to = models.CharField(max_length=255, blank=True, null=True)
    street_to = models.CharField(max_length=255, blank=True, null=True)
    housenr_to = models.CharField(max_length=10, blank=True, null=True)
    zipcode_to = models.CharField(max_length=10, blank=True, null=True)
    city_to = models.CharField(max_length=255, blank=True, null=True)
    class Meta:
        db_table = u'planning'
  • 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-04T22:21:50+00:00Added an answer on June 4, 2026 at 10:21 pm

    Planning.objects.raw() returns RawQuerySet instance, which is different from model instance.

    You need to iterate or slice on the RawQuerySet to access actual model instance and its properties

    qs = planning.objects.raw()
    qs[0].key
    for x in qs:
        x.key
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm making a simple page using Google Maps API 3. My first. One marker
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 am trying to understand how to use SyndicationItem to display feed which is
I used javascript for loading a picture on my website depending on which small
I have a jquery bug and I've been looking for hours now, I can't
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I am reading a book about Javascript and jQuery and using one of the
I want use html5's new tag to play a wav file (currently only supported
I'm using v2.0 of ClassTextile.php, with the following call: $testimonial_text = $textile->TextileRestricted($_POST['testimonial']); ... and

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.