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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T07:30:18+00:00 2026-06-12T07:30:18+00:00

I have an app objects and image objects which are linked to one another

  • 0

I have an app objects and image objects which are linked to one another (the apps have images).

def index(request):
    latest_apps_list = App.objects.all().exclude(approved=False).order_by('name')[:20]
    app_images = Image.objects.filter(app__in=latest_apps_list).order_by('app__name')[:20]
    t = loader.get_template('apps/index.html')
    c = Context({
        'latest_apps_list': latest_apps_list,
        'app_images': app_images
    })
    return HttpResponse(t.render(c))

Now I want to loop through those images in my template. How would I do that with both variables? I tried using zip(), but this returned mysql errors as it calls for unsupported db queries. Is there another way?

Currently I have:

{% for app in latest_apps_list %}

...{{ app.name }}

{% endfor %}

This works. Of course, it doesn’t return the images urls. (I’m using sorl-thumbnail btw.)

UPDATE Perhaps I’m just going about doing this the wrong way. Here’s how I have my model:

class App(models.Model):
    name = models.CharField(max_length=200)
    # ...

class Image(models.Model):
   app = models.ForeignKey(App)
   image = models.ImageField(upload_to = "apps")

And my view is in the original part of the post above. It seems like I should somehow be making the app’s properties and the image properties all one thing, without the need to zip in the view. Is this possible?

UPDATE 2 I solved this by greatly simplifying how the model is created. Here’s what I did in case anyone else is trying to do this.

apps/admin.py: the image object is included as an ordinary field.

class AppAdmin(admin.ModelAdmin):
   fieldsets = [
      ('Basic', {'fields':['name','desc','price','approved','image']}),
      ('Author',        {'fields':['docs_url', 'preview_url']}),
   ]
   list_display = ('name', 'desc', 'price', 'approved')


admin.site.register(App, AppAdmin)

apps/models.py: Just make image part of the app itself. No foreign keys needed.

class App(models.Model):
    name = models.CharField(max_length=200)
    # ...
    image = models.ImageField(upload_to = "apps")

apps/views.py: Now the view just has one object to loop through. No weird sql queries needed.

def index(request):
    latest_apps_list = App.objects.all().exclude(approved=False).order_by('name')[:20]
    t = loader.get_template('apps/index.html')
    c = Context({
        'latest_apps_list': latest_apps_list,
    })
    return HttpResponse(t.render(c))
  • 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-12T07:30:19+00:00Added an answer on June 12, 2026 at 7:30 am

    you should zip them in the view, and pass that zipped object to the template, and then iterate through them.

    view:

    def index(request):
        latest_apps_list = list(App.objects.all().exclude(approved=False).order_by('name')[:20])
        app_images = Image.objects.filter(app__in=latest_apps_list).order_by('app__name')[:20]
        t = loader.get_template('apps/index.html')
        c = Context({
            'zipped_app_list': zip(latest_apps_list, list(app_images))
        })
        return HttpResponse(t.render(c))
    

    template:

    {% for app, image in zipped_app_list %}
        {{ app }}
        {{ image}}
    {% endfor %}
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

in my winforms app, I have a Queue which contains objects: Queue<MyObj> _queuedRows =
I have app with two sites, one where design is done and other which
I have an app with array of objects, which i archived and unarchived -(id)initWithCoder:(NSCoder
In my app I have a scrollview which has some objects like an imageview,
In my app, I have a bunch of images in my drawable folder which
I have an app which downloads images from a server, stores them on the
I have an Image element in my WP7.5 Silverlight app for which I tried
I should like to have an android app which has its background image on
I have an android app where the user paints, moves and reshapes some objects
I have several objects in my app that can become nil at some point

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.