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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T19:26:21+00:00 2026-05-31T19:26:21+00:00

I have a model.py like this: class EventTypeCategory(models.Model): name = models.CharField(max_length=50, verbose_name=Name) user =

  • 0

I have a model.py like this:

class EventTypeCategory(models.Model):

      name = models.CharField(max_length=50, verbose_name="Name")
      user = models.ForeignKey(User, verbose_name="User")
      Message_slug = models.SlugField(blank=True, verbose_name="Message")
      sub_categories = models.ForeignKey('self', verbose_name="Self-Categories", null =True, blank = True)

Whereas sub_categories field are foreign key to itself

I have a view.py like this:

@login_required
def eventcateg_detail(request):
    ca = EventTypeCategory.objects.values()
    return render_to_response('events/categ.html',{
        'obj': ca,
        })

whereas ca returns a dictionary as follow:

[{'Message_slug': u'ngcg', 'sub_categories_id': 124L, 'user_id': 1L, 'id': 146L, 'name': u'ngcg'}, {'Message_slug': u'lkn', 'sub_categories_id': 146L, 'user_id': 1L, 'id': 149L, 'name': u'lkn '}] 

I want to print values of “Sub-categories ,Message” and “name” from each dictionary content at categ.html. Whereas sub_categories are returning “id” ( foreign key to pointing itself). I am newbie at Django and also had look similar questions but it didn’t work for me 🙁

data should be print like this at categ.html:

Message:    Name:    Sub-categories:
ngcg        ngcg      (values which refer to foriegn key)
  • 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-31T19:26:22+00:00Added an answer on May 31, 2026 at 7:26 pm

    Usually, We use QuerySet.all(), which return model-instance objects, instead of QuerySet.values().

    If you have a field called foo that is a ForeignKey, the default
    values() call will return a dictionary key called foo_id, since this
    is the name of the hidden model attribute that stores the actual value
    (the foo attribute refers to the related model).

    Check the doc:
    django.db.models.query.QuerySet.values.

    @login_required
    def eventcateg_detail(request):
        ca = EventTypeCategory.objects.all()
        return render_to_response('events/categ.html',{
            'objs': ca,
            })
    

    Now, the obj is a EventTypeCategory instance.

    {% for obj in objs %}
        {{obj.Message_slug}}, {{obj.name}}, {{obj.sub_categories.name}}
        ngcg,                 ngcg,         (name of instance which refer to foriegn key)
    {% endfor %}
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have model like this: class Kaart(models.Model): name = models.CharField(max_length=200, verbose_name=Kaardi peakiri, help_text=Sisesta kaardi
I have a simple model like this one: class Artist(models.Model): surname = models.CharField(max_length=200) name
I have a model like this: class database(models.Model): db_name = models.CharField('Name', max_length=20) server =
I have a model that looks like this: class Category(models.Model): name = models.CharField(max_length=60) class
For example, I have a model like this: Class Doggy(models.Model): name = models.CharField(u'Name', max_length
I have a model like this class Ask(models.Model): name = models.CharField(max_length=500) designation = models.CharField(max_length=200,
I have a model like this: class Tour(models.Model): Name=models.CharField(max_length=100) Count=models.SmallIntegerField() ActionDate=models.DateTimeField(editable=False) ActionUser=models.ForeignKey(User,editable=False) StatusType=models.ForeignKey(StatusType) now
I have a model class like this: class Note(models.Model): author = models.ForeignKey(User, related_name='notes') content
I have a model that is something like this: class Input(models.Model): details = models.CharField(max_length=1000)
I have models like this: class IdfPracownicy(models.Model): nazwa = models.CharField(max_length=100) class IdfPracaOpinie(models.Model): nazwa =

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.