Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I need to know a bit more to answer your question properly, but here are some ideas that might help you. I'm making the assumption that <code>photos_list</code>, <code>places_list</code> and <code>events_list</code> are all objects of different classes that are Django models.</p> <p><strong>Option 1: Define a method on each class that determines the type of the object</strong></p> <p>For example, define a <code>content_type</code> method on each model, like this:</p> <pre><code>class Photo(models.Model): def type(self): return 'photo' </code></pre> <p>And then check this in your template:</p> <pre><code>{% for item in result_list %} {% if item.type == "photo" %} ... {% elif item.type == "place" %} ... {% else %} ... {% end %} {% endfor %} </code></pre> <p><strong>Option 2: Define a <code>render</code> method on each class</strong></p> <p>This is probably much uglier, but you could define a <code>render</code> method on each object that returns the complete HTML you want to spit out for that object. Then it's a case of doing this in your template:</p> <pre><code>{% for item in result_list %} {{ item.render }} {% endfor %} </code></pre> <p><strong>Sidenote: Consider inheritance</strong></p> <p>It sounds like photos, places and events are all things that could appear in the same feed, and as such they might share some common fields (like <code>posted_at</code>). There are various things you need to consider with regard to this, so it's probably best to look at the <a href="https://docs.djangoproject.com/en/dev/topics/db/models/#model-inheritance" rel="nofollow">Django documentation on model inheritance</a>.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload