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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T07:06:11+00:00 2026-05-26T07:06:11+00:00

I need to display several models name & objects in a template Here is

  • 0

I need to display several models name & objects in a template

Here is my view

def contents(request):
  """Lists Objects"""
  objects = [
    Model1.objects.all(),
    Model2.objects.all(),
    Model3.objects.all(),
    Model4.objects.all(),
    ...
  ]
  return render_to_response('content/contents.html', objs
  , context_instance=RequestContext(request)
  )

My template

{% for objs in objects %}
  <div class="object">
    <div class="object_name">{{ get_verbose_name objs.0 }}</div>
    <ul>
    {% for obj in objs %}
      <li>{{ obj }}</li>
    {% endfor %}
    </ul>
  </div>
{% endfor %}

And my template filter

@register.simple_tag
def get_verbose_name(object):
  return object._meta.verbose_name_plural

This works only if there is at least one obj for each Model in the database.
How can I get the verbose name of each Model if there is no data ?

  • 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-26T07:06:12+00:00Added an answer on May 26, 2026 at 7:06 am

    You are trying to get a model from the first object in the list. This way, if this object does not exist, you won’t get anything.

    Try to use a query set instead:

    {{ get_verbose_name objs }}
    
    @register.simple_tag
    def get_verbose_name(queryset):
      return queryset.model._meta.verbose_name_plural
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

i am developing one application with map view i need display the weather depends
In the QT application we develop we need to display several 'Viewer windows' (to
For an app that I am writing I need to display several views (in
I have several places where I need to display an alert and handle the
I need to display in my program number of similar statistics, like: Name /
I have a List collection of my objects. I need to display this collection
I need to display a google map with several markers. The problem I have
I need to display several graphs which have a common X Axis and a
I'm positioning a VideoView with AbsoluteLayout (I need to display it on several places
I have several tables from which I need to display data. Schools ------- id

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.