Note that there are some explanatory texts on larger screens.

plurals
  1. POViewing subset of objects in Django, Views, URLs, Models
    primarykey
    data
    text
    <p>I know this is a very basic concept in Django, and I have tried the tutorial but it is not working. I am working on a comic book database with the models set like this (at least, a sample of two of the models):</p> <pre><code>Class Title(models.Model): title = models.CharField(max_length=256) vol = models.IntegerField("Vol.") slug = models.SlugField(blank=True, null=True) #desc = models.CharField(max_length=256) class Meta: ordering = ['title'] def get_absolute_url(self): return "/comics2/title/%s" % self.slug def __unicode__(self): return self.title class Issue(models.Model): title = models.ForeignKey(Title) number = models.IntegerField(help_text="Enter the number only. Do not include the hashtag.") writer = models.ManyToManyField(Creator) </code></pre> <p>What I am trying to do is create a page that shows a list of all the issues within that Title.</p> <p>But, I have it setup in the views like this:</p> <pre><code>class AstonishingXMenIssueListView(ListView): context_object_name = "astonishing_list" queryset = Issue.objects.filter(title__title="Astonishing X-Men").order_by("number") template_name = "comics2/astonishing_list.html" </code></pre> <p>My urls.py look like this:</p> <pre><code>(r'^comics2/title/(?P&lt;title_slug&gt;[-\w]+)/$', AstonishingXMenIssueListView.as_view( )), </code></pre> <p>Of course, going to /uncanny-xmen-v1/ shows the same thing as the Astonishing link above.</p> <p>Obviously, this is not a practical way to list issues by title for future issues and titles, so I need it setup so that I don't have to individually do this. Now, I have tried following the Django generic views tutorial, but I got an index tuple error. </p> <p>I've tried this, but it doesn't work. This is what gets me the index tuple error.</p> <pre><code>class IssuesByTitleView(ListView): context_object_name = "issues_by_title_list" template_name = "comics2/issues_by_title.html", def get_queryset(self): title = get_object_or_404(Title, title__iexact=self.args[0]) return Issue.objects.filter(title=title) </code></pre> <p>Any ideas? And can someone please reply in baby-language, as I am new to Django and Python, so simply telling me to look at the Tutorial again isn't going to help. So, maybe writing out the code would help! Thanks!</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload