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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T09:14:44+00:00 2026-05-24T09:14:44+00:00

I have two models for Publications and Employees: class Publication(models.Model): BOOK_CHAPTER = 1 ARTICLE

  • 0

I have two models for Publications and Employees:

class Publication(models.Model):
    BOOK_CHAPTER = 1
    ARTICLE = 2
    PUBLICATION_CHOICES = (
        (BOOK_CHAPTER, 'Book chapter'),
        (ARTICLE, 'Article'),
    )
    publication_type = models.IntegerField(choices=PUBLICATION_CHOICES)
    article_title = models.CharField(max_length=250, help_text='Limited to 250 characters. May also be used for book chapter titles.')
    slug = models.SlugField(help_text='Suggested value automatically generated from title.')
    primary_author = models.ForeignKey('Employee', limit_choices_to={'employee_type': 1}, help_text='Most of the time, this will be the faculty member to whom the publication is tied.')
    authors = models.CharField(max_length=250, help_text='Limited to 250 characters. Please adhere to accepted format for style. Include current employee in this list.', blank=True)
    journal_name = models.CharField(max_length=250, help_text='Limited to 250 characters. May also be used for book titles.')
    journal_volume = models.IntegerField(max_length=3, blank=True, null=True)
journal_issue = models.IntegerField(max_length=3, blank=True, null=True)
    journal_pub_date = models.DateField(help_text='To specify only the year, simply type in the date using the following format: 2011-01-01.')
    journal_page_range = models.CharField(max_length=50, help_text='Limited to 50 characters.', blank=True)
    editors = models.CharField(max_length=250, help_text='Limited to 250 characters.', blank=True)
    publisher = models.CharField(max_length=250, help_text='Limited to 250 characters.', blank=True)
    location_of_publication = models.CharField(max_length=250, help_text='Limited to 250 characters.', blank=True)
    abstract = models.TextField(blank=True)
    notes = models.TextField(blank=True)
    external_link = models.URLField(blank=True, help_text='Link to the article on the publication\'s website.')
    downloadable_version = models.ForeignKey(Document, blank=True, null=True)

And:

class Employee(models.Model):
    FACULTY = 1
    ADMINISTRATIVE_SUPPORT = 2
    RESEARCH_SUPPORT = 3
    POSTDOCS = 4
    EMPLOYEE_CHOICES = (
        (FACULTY, 'Faculty'),
        (ADMINISTRATIVE_SUPPORT, 'Administrative support'),
        (RESEARCH_SUPPORT, 'Research support'),
        (POSTDOCS, 'Postdocs'),
    )
    user = models.ForeignKey(User, unique=True, help_text="Select a user if this employee is able to update their own profile information.", blank=True, null=True)

    first_name = models.CharField(max_length=200)
    middle_name = models.CharField(max_length=50, help_text="Limited to 50 characters.", blank=True)
    last_name = models.CharField(max_length=200)

    slug = models.SlugField(unique=True, help_text='Will populate from a combination of the first, middle and last names.')

    title = models.CharField(max_length=200, help_text="Limited to 200 characters.")
    previous_position = models.CharField(max_length=350, help_text="Limited to 350 characters.", blank=True)

    email = models.EmailField()
    office_phone_number = PhoneNumberField(null=True, blank=True)
    mobile_phone_number = PhoneNumberField(null=True, blank=True)
    office = models.CharField(max_length=50, help_text="Your office number or room name. Limited to 50 characters.", blank=True)
    website = models.URLField(blank=True)

    job_description = models.TextField(help_text='A description of your work or research. No HTML is allowed. If formatting is needed, please use <a href="http://daringfireball.net/projects/markdown/syntax">Markdown syntax</a>.', blank=True)
    job_description_html = models.TextField(blank=True, editable=False)

    job_description_summary = models.CharField(max_length=250, help_text="A brief summary of your work or research. Limited to 250 characters.")

    is_currently_employed = models.BooleanField(default=True)
    related_links = generic.GenericRelation(RelatedLink, blank=True)
    employee_type = models.IntegerField(choices=EMPLOYEE_CHOICES)

    photo = models.ImageField(upload_to='images/profiles/mugshots', blank=True)
    lead_image = models.ImageField(upload_to='images/profiles/graphics', blank=True)

    resume_or_cv = models.ForeignKey(Document, blank=True, null=True)

    sites = models.ManyToManyField(Site)

I’d like to have a view to display all publications for an employee. Here’s the view I’m working with now:

from django.shortcuts import get_object_or_404
from django.views.generic import ListView
from cms.employees.models import Employee, Publication

class EmployeePublicationsListView(ListView):

    context_object_name = "publication_list"
    template_name = "employees/publications_by_employee.html",

    def get_queryset(self):
        self.primary_author = get_object_or_404(Employee, slug__iexact=self.args[0])
        return Publication.objects.filter(primary_author=self.primary_author)

    def get_context_data(self, **kwargs):
        context = super(EmployeePublicationsListView, self).get_context_data(**kwargs)
        context['primary_author'] = self.primary_author
        return context

Here’s the URL pattern I’m using currently where I’m passing the slug from the Employee model into the URL for a list of all publications by that employee:

from django.conf.urls.defaults import patterns, include, url
from cms.employees.models import Employee, Publication
from django.views.generic import ListView, DetailView
from cms.employees.views import EmployeePublicationsListView, EmployeeMentionsListView

urlpatterns = patterns('',
    (r'^(?P<slug>[-\w]+)/publications/$', EmployeePublicationsListView.as_view()),

)

But I’m getting a IndexError at /employees/joe-reporter/publications/ for tuple index out of range. Here’s the traceback:

Environment:


Request Method: GET
Request URL: http://127.0.0.1:8000/employees/joe-reporter/publications/

Django Version: 1.3
Python Version: 2.6.1
Installed Applications:
['django.contrib.auth',
 'django.contrib.contenttypes',
 'django.contrib.sessions',
 'django.contrib.sites',
 'django.contrib.messages',
 'django.contrib.staticfiles',
 'django.contrib.flatpages',
 'django.contrib.admin',
 'django.contrib.admindocs',
 'django.contrib.sitemaps',
 'django.contrib.humanize',
 'django.contrib.redirects',
 'django.contrib.webdesign',
 'cms.news',
 'cms.media',
 'cms.categories',
 'cms.related_links',
 'cms.employees',
 'cms.static_media',
 'cms.places',
 'cms.events',
 'cms.jobs',
 'cms.press',
 'cms.topics',
 'cms.featured',
 'tagging',
 'template_utils',
 'contact_form',
 'cms.research',
 'shorturls']
Installed Middleware:
('django.middleware.common.CommonMiddleware',
 'django.contrib.sessions.middleware.SessionMiddleware',
 'django.middleware.csrf.CsrfViewMiddleware',
 'django.contrib.auth.middleware.AuthenticationMiddleware',
 'django.contrib.messages.middleware.MessageMiddleware',
 'django.contrib.redirects.middleware.RedirectFallbackMiddleware')


Traceback:
File "/Library/Python/2.6/site-packages/django/core/handlers/base.py" in get_response
  111.                         response = callback(request, *callback_args, **callback_kwargs)
File "/Library/Python/2.6/site-packages/django/views/generic/base.py" in view
  47.             return self.dispatch(request, *args, **kwargs)
File "/Library/Python/2.6/site-packages/django/views/generic/base.py" in dispatch
  68.         return handler(request, *args, **kwargs)
File "/Library/Python/2.6/site-packages/django/views/generic/list.py" in get
  116.         self.object_list = self.get_queryset()
File "/Users/pbeeson/Sites/django_projects/cms/../cms/employees/views.py" in get_queryset
  16.         self.primary_author = get_object_or_404(Employee, slug__iexact=self.args[0])

Exception Type: IndexError at /employees/joe-reporter/publications/
Exception Value: tuple index out of range

What am I doing wrong?

  • 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-24T09:14:44+00:00Added an answer on May 24, 2026 at 9:14 am

    Since you are using a named group in your urlpattern regex, the slug is passed as a keyword argument, not a positional argument. So you get it from self.kwargs['slug'] rather than self.args[0].

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

Sidebar

Related Questions

I have the following two models class Author(Model): name = CharField() class Publication(Model): title
I have two models, Article and Post that both inherit from a base model
I have two models: Play and PlayParticipant , defined (in part) as: class PlayParticipant(models.Model):
Got a question. Say I have two models in a many-to-many relationship (Article, Publication).
I have two models. Comment and his Subcomments: class Comment(models.Model): .... author = models.CharField(max_length=80)
I have two models in Django like follows(in pseudo code) class Medicine(db.Model): field_1 =
I have two models like this: class Collar(models.Model): num_tags = models.BigIntegerField() class Dog(models.Model): num_legs
I have two models for store and city: class City(models.Model): name = models.CharField() slug
I have two models lets say: class superfields(Model): fieldA = models.FloatField() fieldB = models.FloatField()
I have two models in relation one-to-many: class Question(db.Model): questionText = db.StringProperty(multiline=False) class Answer(db.Model):

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.