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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T22:41:46+00:00 2026-05-31T22:41:46+00:00

I have a function like this: def eventcateg_detail(request): ca = EventTypeCategory.objects.values() for i in

  • 0

I have a function like this:

def eventcateg_detail(request):
    ca = EventTypeCategory.objects.values()
    for i in range(0, len(ca)):
       pk_sub = ca[i]['sub_categ_id']
       if (pk_sub!=None):
          category = EventTypeCategory.objects.get(id = pk_sub)
          category = category.name
    return render(request,"events/categ.html",{
       'obj': ca
        })

Definition of above function:

Fist i am getting a dictionary in ca variable i.e.

[{'Message_slug': u'critical', 'sub_categ_id': None, 'user_id': 1L, 'id': 190L, 'name': u'Critical'}, {'Message_slug': u'information', 'sub_categ_id': 190L, 'user_id': 1L, 'id': 192L, 'name': u'Information'}]

Now i want to get a value defining in sub_categ_id for each content. I got this in pk_sub variable. As you can see that pk_sub is returning an id (which is foreign key to itself). I want to get all these values which pointing to that pk_sub. I am also getting this :

Critical
Information
Amit Pal

Now i want to append this category.name into a list. So that i can easily pass to my template. How should i do this?

I tried by putting following code at next line:

categories = categories.append(category)

but it didn’t work 🙁

  • 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-31T22:41:47+00:00Added an answer on May 31, 2026 at 10:41 pm

    Two things:

    1. You can iterate over list directly, rather than by index: for category in ca:. In the body of that loop, category will be bound to each item in ca.
    2. You never define categories, so you cannot append to it; in any case, list.append returns None, and destructively modifies the list, so you would have to omit the assignment.

    Finally, as a matter of style one usually uses x is not None rather than != when testing for None.

    Update: Note @agf’s comment, which describes the proper way to use the Django ORM to perform this task.

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

Sidebar

Related Questions

I have a function friend_exists like this: def friend_exists(request, pid): result = False try:
Heyy there, i have for example a view function like this: def profile_view(request, id):
Suppose I have a function like this: def getNeighbors(vertex) which returns a list of
I have a function that looks like this: def post_count(self): return self.thread_set.aggregate(num_posts=Count('post'))['num_posts'] I only
I have a save function within my Python program which looks like this: def
I have a setup looking something like this: def foo_decorator(function): @wraps(function) def decorator(*args, **kwargs):
Let's say I have a function with a signature like this: def tsadd(key: Any,
I have a function that looks like this: def getCurrentShow(hour=(localtime().tm_hour),day=datetime.datetime.now().strftime('%A')): return Schedule.objects.get(hour=hour,day=day).show so I
Assuming I have a decorator and a wrapped function like this: def squared(method): def
I have a generator function that goes something like this: def mygenerator(): next_value =

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.