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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T17:00:41+00:00 2026-06-01T17:00:41+00:00

I have a simple model like this class UserType( models.Model ) : def __unicode__(

  • 0

I have a simple model like this

class UserType( models.Model ) :
    def __unicode__( self ) :
        return self.name

    TYPE_CHOICES = (
        ( 'ad', 'administrator'    ),
        ( 'mo', 'moderator'        ),
        ( 'vi', 'viewer'           ),
        ( 'pm', 'property manager' ),
        ( 'po', 'property owner'   ),
        ( 'vm', 'vendor manager'   ),
        ( 've', 'vendor'           ),
        ( 'te', 'tenant'           ),
    )

    name = models.CharField( max_length = 2, choices = TYPE_CHOICES )

In the admins.py, I set filter_horizontal = ( 'user_types', ) for UserProfile, which has a ManyToManyField to UserType. But in the UserProfile admin page, the horizontal filter for M2M only shows the short-name of the tuple:

Also in a template, I want to show a list of user types a particular user has. So my template code looks like this

User type:
<ul>
    {% if user_object.profile.user_types.all %}
        {% for user_type in user_object.profile.user_types.all %}
            <li>{{ user_type|capfirst }}</li>
        {% endfor %}
    {% else %}
        <li>No user type</li>
    {% endif %}
</ul>

And on the template, it displays only the short-name. I know normally I could show it the long-name by doing something like {{ get_user_type_display }}, but in this case for M2M, it doesn’t work.

So my question is two-fold:

  1. How do I display the long-name of a M2M choice/tuple in the admin page?
  2. How do I display the long-name in a M2M choice/tuple in a template?
  • 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-01T17:00:43+00:00Added an answer on June 1, 2026 at 5:00 pm

    Try the following:

    class UserType( models.Model ) :
        TYPE_CHOICES = (
            ( 'ad', 'administrator'    ),
            ( 'mo', 'moderator'        ),
            ( 'vi', 'viewer'           ),
            ( 'pm', 'property manager' ),
            ( 'po', 'property owner'   ),
            ( 'vm', 'vendor manager'   ),
            ( 've', 'vendor'           ),
            ( 'te', 'tenant'           ),
            )
        STR_CHOICES = { key : value for (key,value) in TYPE_CHOICES }
    
        name = models.CharField( max_length = 2, choices = TYPE_CHOICES )
    
        def __str__(self):
            return self.STR_CHOICES[self.name]
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a simple model like this one: class Artist(models.Model): surname = models.CharField(max_length=200) name
I have a simple model which looks like this: class Group(models.Model): name = models.CharField(max_length
I have a model that looks like this: class Category(models.Model): name = models.CharField(max_length=60) class
I have some simple Django Models like this: class Event(models.Model): # some stuff class
Django newbie here. I have two simple models like this: class Fluff(models.Model): # ....
Hi Suppose I have a simple model class like this: class TestModel(models.Model): testkey =
Hay, i have a simple model class Manufacturer(models.Model): name = models.CharField() car_count = models.IntegerField()
I have Django model that looks like this: class Categories(models.Model): Model for storing the
Assume I have such simple model: class Foo(models.Model): name = models.CharField(max_length=25) b_date = models.DateField()
I have a simple model with news and categories: class Category(models.Model): name = models.CharField()

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.