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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T15:27:43+00:00 2026-05-23T15:27:43+00:00

I’m working on a comic book database and there are main covers and variant

  • 0

I’m working on a comic book database and there are main covers and variant covers. I have a page that shows all the Main covers, but I’d like to combine the variant covers too, in order of the publication date. This is what part of my models look like:

class Image(models.Model):
    CATEGORY_CHOICES = (
    ('Cover', 'Cover'),    
    ('Scan', 'Scan'),
    ('Other', 'Other'),
    )
    title = models.CharField(max_length=128)
    number = models.CharField(max_length=20, help_text="Do not include the '#'.")
    image = models.ImageField(upload_to="images/")
    category = models.CharField(max_length=10, choices=CATEGORY_CHOICES)
    ### The variant cover is determined by the category_choice 'Cover'. ###
    contributor = models.ManyToManyField(Contributor, blank=True, null=True)
    date_added = models.DateField(auto_now_add=True, auto_now=True)    
    def __unicode__(self):
        return self.title        
    class Meta:
        ordering = ['title']

class Issue(models.Model):
    CATEGORY_CHOICES = (
    ('Major', 'Major'),    
    ('Minor', 'Minor'),
    ('Cameo', 'Cameo'),
    ('Other', 'Other'),
    )
    title = models.ForeignKey(Title)
    number = models.CharField(max_length=20, help_text="Do not include the '#'.")
    pub_date = models.DateField(blank=True, null=True)
    cover_image = models.ImageField(upload_to="covers/", blank=True, null=True)
    ### This would be where the main image goes. ^^^ ###
    images = models.ManyToManyField(Image, related_name="images_inc", blank=True, null=True)
    ### This is where the variant covers go.^^^  ### 
    has_emma = models.BooleanField(help_text="Check if Emma appears on the cover.")

My views.py for the main cover page looks like this:

def covers(request):
    sort_by = request.GET.get('sort', 'pub_date')
    if sort_by not in ['-date_added', 'date_added', '-pub_date', 'pub_date']:
        sort_by = '-date_added'
    issues = Issue.objects.filter(has_emma=True).order_by(sort_by).select_related(depth=1)
    return render_to_response('comics/covers.html', {'issues': issues}, context_instance=RequestContext(request))

But I would like to display the variant covers too and not just the cover_image. Is there a way to do this? Maybe with something image and then filtering the category (of the Image model by cover)?

I, of course, can do this:

def variants(request):
    Issue.objects.filter(has_emma=True).order_by(sort_by).select_related(depth=1)
    images = Image.objects.filter(category='Cover').order_by('id')
    return render_to_response('comics/variants.html', {'images': images}, context_instance=RequestContext(request))

But that does not give me enough flexibility as def covers does, and I want them combined and sorted by pub_date, like def covers.

Edit

models.py:

class Image(models.Model):
    CATEGORY_CHOICES = (
    ('Cover', 'Cover'),    
    ('Scan', 'Scan'),
    ('Other', 'Other'),
    )
    title = models.CharField(max_length=128)
    image = models.ImageField(upload_to="images/")
    category = models.CharField(max_length=10, choices=CATEGORY_CHOICES)
    date_added = models.DateField(auto_now_add=True, auto_now=True)    
    def __unicode__(self):
        return self.title        
    class Meta:
        ordering = ['title']


class Issue(models.Model):
    title = models.ForeignKey(Title)
    number = models.CharField(max_length=20)
    ######
    has_emma = models.BooleanField(help_text="Check if cover appearance.")    
    cover_image = models.ImageField(upload_to="covers/", blank=True, null=True)
    images = models.ManyToManyField(Image, related_name="images_inc", blank=True, null=True)
    ######
    def get_images(self):
        ''' Returns a list of all cover images combined,
            "main" cover image first.
        '''
        images = [self.cover_image]
        for image in self.images.filter(category='Cover'):
            images.append(image.image)
        return images   

views.py:

def covers(request):
    sort_by = request.GET.get('sort', '-pub_date')
    if sort_by not in ['-date_added', 'date_added', '-pub_date', 'pub_date']:
        sort_by = '-date_added'         
    issues = Issue.objects.filter(has_emma=True).order_by(sort_by)
    return render_to_response('template.html', {'issues': issues,}, context_instance=RequestContext(request))

template.html:
{% for issue in issues %}{% for image in issue.get_images %}{{ image.image }}{% endfor %}{% endfor %} – displays nothing, however, {% for issue in issues %} {% for image in issue.get_images %} {{ issue.cover_image }} {% endfor %} {% endfor %} will repeatedly display the cover_image of the Issue model if there are variant covers, which are categorized in the Image model.

What can I do to fix this, so that it shows everything correctly? And for the record again, I want it to display the {{ cover_image }} (from the Issue model) and the {{ image.image }} as defined by the Image model combined.

  • 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-23T15:27:44+00:00Added an answer on May 23, 2026 at 3:27 pm

    If I understand your problem correctly, one way to solve it would be adding a method to Issue class like this:

    class Issue(models.Model):
        # fields...
    
        def get_images(self):
            ''' Returns a list of all cover images combined,
                "main" cover image first.
            '''
            images = [self.cover_image]
            for image in self.images.filter(category='Cover'):
                images.append(image.image)
            return images
    

    Then, in your template, you can do, for example, {% for image in issue.get_images %}....

    (If it’s not exactly what you need—then, I think, it would be better if you provide some template code as an example of what you’re trying to achieve.)

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I have a French site that I want to parse, but am running into
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I have a text area in my form which accepts all possible characters from
I have a reasonable size flat file database of text documents mostly saved in
I'm working with an upstream system that sometimes sends me text destined for HTML/XML
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have just tried to save a simple *.rtf file with some websites and
I want to count how many characters a certain string has in PHP, but

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.