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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T11:15:02+00:00 2026-05-21T11:15:02+00:00

This is what part of my models look like: class Character(models.Model): name = models.CharFied()

  • 0

This is what part of my models look like:

class Character(models.Model):
    name = models.CharFied()

class Issue(models.Model):
    character = models.ManyToManyField(Character, related_name="appearances", blank=True, null=True)

What I’m trying to do is, when you go to a character’s page, it will show all the Issues that Character is in.

This is how my view is setup:

def character(request, character_slug):
    character = get_object_or_404(Character, slug=character_slug)            
    return render_to_response('comics2/character_detail.html', {'character': character}, context_instance=RequestContext(request)

In the template:

{{ character.name }}

works

I tried this:

class CharactersView(ListView):
    context_object_name = "character_list"
    template_name = "comics2/character_detail.html"    
    def get_queryset(self):
        character = get_object_or_404(Character, slug=self.kwargs['character_slug'])
        return Issue.objects.filter(character=character)

But it doesn’t work..

But how would I go about in the template displaying all the issues that character has appeared in? For example:

Character Name
Issue #1
Issue #2,
etc.

I feel this is something very simple, but I’m not getting it. I’ve scoured the Internet for answers, but can’t seem to find things that work. So, let me know what’s going and I prefer baby talk and possibly the actual code…thanks!

  • 1 1 Answer
  • 2 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-21T11:15:03+00:00Added an answer on May 21, 2026 at 11:15 am

    You are looking for following a relationship backwards

    {% for issue in character.appearances.all %}
        {{ issue }}
    {% endfor %}
    

    since you set a related name, otherwise, character.issue_set.all is the default. You can also add the issues to the context by getting the related set in the view.

    full example:

    models.py

    class Character(models.Model):
        name = models.CharField()
        slug = models.SlugField()
    
        def __unicode__(self):
            return "%s" % self.name
    
    class Issue(models.Model):
        title = models.CharField()
        volume = models.IntegerField()
        character = models.ManyToManyField(Character, related_name="appearances", blank=True, null=True)
    
        def get_absolute_url(self):
            ...
    

    views.py

    def character(request, character_slug):
        character = get_object_or_404(Character, slug=character_slug)
        issues = character.appearances.all()
    
        context = {'character': character,
                   'issues':issues,}                           
    
        return render_to_response('comics2/character_detail.html', 
            context_instance=RequestContext(request)
    

    template.html

    <h1>Appearances of {{ character }}<h1>
    <table>
        <thead>
            <tr>
                <th>Title</th>
                <th>Volume</th>
            </tr>
        </thead>
        <tbody>
            {% for issue in issues %}
            <tr>
                <td><a href="{{ issue.get_absolute_url }}>{{ issue.title }}</a></td>
                <td>{{ issue.volume }}</td>
            </tr>
            {% endfor %}
        </tbody>
    </table>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Given the following models (cut down for understanding): class Venue(models.Model): name = models.CharField(unique=True) class
I have this part of the function : $jQ('.product-collateral .product-tabs li').each(function(index){ $jQ(this).attr('id', $jQ(this).find('h3').attr('class')); if(index
Let's take the Django tutorial. In the first part we can find this model:
This part of my code works fine: #include <stdio.h> int main(){ //char somestring[3] =
This part of my code is used to award a grade to a student
This part of an app that I am working on, I have the following
It seems that this part of my code is where the exception occurs: c
For some reasons this part where I fetch JSON data from following url will
You may skip this part: I am creating an application where the client needs
I have this part of code in my functions.php: function cc_admin_enqueue_scripts($hook) { $file_dir=get_bloginfo('template_directory'); wp_enqueue_script('media-upload');

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.