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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T07:09:50+00:00 2026-06-13T07:09:50+00:00

I have the following issue with Django: My model is defined as follows: from

  • 0

I have the following issue with Django:

My model is defined as follows:

from django.db import models

class SettingSection(models.Model):
    section = models.CharField(max_length=20)
    def __unicode__(self):
        return self.section

class SettingParam(models.Model):
    section = models.ForeignKey(SettingSection)
    param = models.CharField(max_length=20, unique=True)
    description = models.CharField(max_length=200, blank=True)
    def __unicode__(self):
        return self.param

class SettingPreset(models.Model):
    preset = models.CharField(max_length=20, unique=True)
    current = models.BooleanField()
    def __unicode__(self):
        return self.preset

class SettingValue(models.Model):
    preset = models.ForeignKey(SettingPreset)
    param = models.ForeignKey(SettingParam)
    value = models.CharField(max_length=100, blank=True)
    def __unicode__(self):
        return self.value

I have following error when trying to access any attribute of my SettingValue object:

>>> from settings.models import *
>>> preset = SettingPreset.objects.get(current=True)
>>> for section in SettingSection.objects.all():
...     for param in section.settingparam_set.all():
...             v = SettingValue.objects.filter(preset=preset, param=param)
...             print v.id, v.value
... 
Traceback (most recent call last):
  File "<console>", line 4, in <module>
AttributeError: 'QuerySet' object has no attribute 'id'

However, the attributes (“id” and “value”) seem to exist:

>>> for section in SettingSection.objects.all():
...     for param in section.settingparam_set.all():
...             v = SettingValue.objects.filter(preset=preset, param=param)
...             print v.values()
... 
[{'value': u'192.168.1.29', 'id': 1, 'preset_id': 1, 'param_id': 1}]
[{'value': u'en1', 'id': 2, 'preset_id': 1, 'param_id': 2}]
[{'value': u'0', 'id': 3, 'preset_id': 1, 'param_id': 3}]
[{'value': u'', 'id': 4, 'preset_id': 1, 'param_id': 4}]
[{'value': u'', 'id': 5, 'preset_id': 1, 'param_id': 5}]

In addition, I’m able to access any of the attributes without applying filters to my object:

>>> for v in SettingValue.objects.all():
...     print v.id, v.value
... 
1 192.168.1.29
2 en1
3 0
4 
5 
  • 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-13T07:09:51+00:00Added an answer on June 13, 2026 at 7:09 am

    The variable v is a queryset, and you cannot access your models attributes via the queryset. Therefore you should try this to access the first element in your queryset:

    for param in section.settingparam_set.all():
        v = SettingValue.objects.filter(preset=preset, param=param)
        print v[0].id, v[0].value #access first element in query set
    

    Or do this to loop over the items in your queryset:

    for param in section.settingparam_set.all():
        v = SettingValue.objects.filter(preset=preset, param=param)
        for item in v:
            print item.id, item.value
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following models: class Tag(models.Model): name = models.CharField(max_length=20) class Entry(models.Model): title =
(Django 1.x, Python 2.6.x) I have models to the tune of: class Animal(models.Model): pass
I am using Django 1.3 and have the following issue: In the Admin list
I currently have a simple model defined, with a photoupload feature using django thumbnails
I have the following snippet in a Django view to render memcache stats: import
The following code gives me an error from django.db import connection cursor = connection.cursor()
I have a bit of a left join issue.. I have the following models
For the following Python code: first.py # first.py from second import Second class First:
I've been updating recently to django 1.3 and got the following issue: I have
I have the following issue related to iterating over an associative array of strings

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.