Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

193
Views
Append does not work in For Loop
first_sale_all_menu             = []

for one_product_category in Product_Category.objects.all().filter(slug__in=('3-pack-items-c', '3-pack-items-b', '3-pack-items', '3-pack-items-d')):
    link_to_mamapedia_cat   = link_to_home_page + one_product_category.get_absolute_url()
    mamapedia_category_name = one_product_category.name
    if (one_product_category.image_for_top_menu != None):
        header_image = link_to_home_page + one_product_category.main_picture.url  # TODO use thumbnail
    else:
        header_image = ''

    first_sale_all_menu.append({
        'menu_children_url'         : link_to_mamapedia_cat,
        'menu_children_title'       : mamapedia_category_name,
        'menu_product_image_src'    : header_image
    })

Somehow that append() method does not work, it is still empty list for first_sale_all_menu.

Just to make sure, even this does not work:

first_sale_all_menu             = []
for one_product_category in Product_Category.objects.all().filter(slug__in=('3-pack-items-c', '3-pack-items-b', '3-pack-items', '3-pack-items-d')):
    link_to_mamapedia_cat   = link_to_home_page + one_product_category.get_absolute_url()
    mamapedia_category_name = one_product_category.name
    if (one_product_category.image_for_top_menu != None):
        header_image = link_to_home_page + one_product_category.main_picture.url  # TODO use thumbnail
    else:
        header_image = ''

    first_sale_all_menu.append({
        'menu_children_url': 'link_to_mamapedia_cat',
        'menu_children_title': 'mamapedia_category_name',
        'menu_product_image_src': 'header_image'
    })

But this works:

first_sale_all_menu             = []
first_sale_all_menu.append({
        'menu_children_url': 'link_to_mamapedia_cat',
        'menu_children_title': 'mamapedia_category_name',
        'menu_product_image_src': 'header_image'
    })

I don't know why, but append() does not work inside my for loop. And yes, link_to_mamapedia_cat, mamapedia_category_name, header_image all have String values.

Ok i got the problem, turns out the query never got executed, wrong Model. Haha.

over 4 years ago · Santiago Trujillo
1 answers
Answer question

0

The point is, very simple, your loop hasn't been executed. You can add an output to check.

first_sale_all_menu             = []

for one_product_category in Product_Category.objects.all().filter(slug__in=('3-pack-items-c', '3-pack-items-b', '3-pack-items', '3-pack-items-d')):
    print(1)
    link_to_mamapedia_cat   = link_to_home_page + one_product_category.get_absolute_url()
    mamapedia_category_name = one_product_category.name
    if (one_product_category.image_for_top_menu != None):
        header_image = link_to_home_page + one_product_category.main_picture.url  # TODO use thumbnail
    else:
        header_image = ''

    first_sale_all_menu.append({
        'menu_children_url'         : link_to_mamapedia_cat,
        'menu_children_title'       : mamapedia_category_name,
        'menu_product_image_src'    : header_image
    })
over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!