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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T08:33:58+00:00 2026-06-01T08:33:58+00:00

so django-model-utils is awesome. I’m on django 1.3 and attempting to use the Inheritance

  • 0

so django-model-utils is awesome.
I’m on django 1.3 and attempting to use the Inheritance Manager.

What I want to accomplish is:
– a queryset to capture all subclasses
– pass this queryset to template
– iterate through this queryset but treat each obj differently depending on the specific subclass

taking the example from the docs if i do:

nearby_places = Place.objects.filter(location='here').select_subclasses()

Once I’m in a template is there a way for me to know what each of the nearby_places is so i can do something different with it? e.g.

{% for np in nearby_places %}
{% if np is a restrautant %}
# do this
{% elif np is a bar %}
# do this
{% endif %}
{% endfor %}

The only thing i can think of right now is if in each of my subclasses I define a method like

def is_restaurant()
    return True

def is_bar()
    return True

etc

Is there some other more elegant way of doing this?

  • 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-01T08:33:59+00:00Added an answer on June 1, 2026 at 8:33 am

    You can add a model method like:

    def classname(self):
        # can't access attributes that start with _  in a template
        return self.__class__.__name__
    

    Then:

    {% if np.classname == 'Restaurent' %}
    {% endif %}
    
    {% if np.classname == 'Bar' %}
    {% endif %}
    
    etc, etc...
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm attempting to dynamically construct some classes which are subclasses of django's models.Model. My
using django 1.4 I have a model with a datetimefield. I imported django.utils.timezone to
I want a Django model to have a date field in which the year,
I have django model which consist of parent child relationship filed I want to
I have a model project_phase : from django.db import models from django.utils import simplejson
I have a model that I want to save in Django Admin class Product(models.Model):
I have a Model and ModelForm like: from django.utils.translation import ugettext_lazy as _ class
When using from django.utils import simplejson on objects of types that derive from db.Model
I want to overwrite the custom objects model manager to only return objects a
Here is a Django model I'm using. class Person(models.Model): surname = models.CharField(max_length=255, null=True, blank=True)

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.