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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T06:08:28+00:00 2026-06-17T06:08:28+00:00

This is the first project I’ve done using Class-based views in django (1.4) and

  • 0

This is the first project I’ve done using Class-based views in django (1.4) and I’m having some trouble with date-based archives not returning URLs. I’ve successfully built several apps in my project (a corporate intranet) that don’t need them, but the ‘news’ part of the site really needs a date-based archive.

The year, month and day archives all seem to work fine, but my individual articles aren’t producing the URLs I think they should. I’m pretty sure the problem is in my get_absolute_url function in models.py, because if I type the URL I want them to have directly django finds and displays the article I want!

Calling get_absolute_url function from a shell I get:

NoReverseMatch: Reverse for 'news_detail' with arguments '('2013', 'Jan', '14', 'another-news-thang')' and keyword arguments '{}' not found.

I’ve read the relevant docs and the specific reference for the DateDetailView but I can’t quite get my head round where I’m going wrong.

My models.py is:

from django.db import models
import datetime
from django.core.urlresolvers import reverse
from django.contrib.auth.models import User
from phone_list.models import Person, Team
from tinymce import models as tinymce_models
from taggit.managers import TaggableManager
from easy_thumbnails.fields import ThumbnailerImageField

class LiveNewsManager(models.Manager):
    def get_query_set(self):
        return super(LiveNewsManager, self).get_query_set().filter(status=self.model.LIVE_STATUS)

class News(models.Model):
    LIVE_STATUS=1
    DRAFT_STATUS=2
    HIDDEN_STATUS=3
    STATUS_CHOICES=(
        (LIVE_STATUS, 'Live'),
        (DRAFT_STATUS, 'Draft'),
        (HIDDEN_STATUS, 'Hidden'),
    )

    # core fields
    headline=models.CharField(max_length=250)
    image = ThumbnailerImageField(
        upload_to='news_images',
        resize_source=dict(size=(700, 500), sharpen=True),
        null=True,
        blank=True,
        help_text = "Optional. Photographs added here are given 'feature' status and should be landscape oriented.",
    )
    image_caption=models.CharField(
        max_length=144,
        blank=True,
        help_text = "DO NOT ADD IF THERE IS NO FEATURE IMAGE",
    )
    story = tinymce_models.HTMLField()
    pub_date=models.DateTimeField(default=datetime.datetime.now)

    # metadata
    writer=models.ForeignKey(Person)
    enable_comments=models.BooleanField(default=True)
    featured=models.BooleanField(default=False)
    slug=models.SlugField(unique_for_date='pub_date')
    status=models.IntegerField(choices=STATUS_CHOICES, default=LIVE_STATUS)

    # categorization
    tags=TaggableManager()

    objects=models.Manager()
    live=LiveNewsManager()

    class Meta:
        verbose_name_plural='News articles'
        ordering=['-pub_date']

    def pictures(self):
        try:
            return [self.image]
        except:
            pass

    def get_absolute_url(self):
        return reverse ('news_detail', args = [str(self.pub_date.strftime("%Y")), str(self.pub_date.strftime("%b")), str(self.pub_date.strftime("%d")), str(self.slug)])

    def __unicode__(self):
        return self.headline

And my urls.py is:

from django.conf.urls import patterns, include, url
from haystack.forms import ModelSearchForm
from haystack.query import SearchQuerySet
from haystack.views import SearchView
from django.views.generic import ArchiveIndexView, YearArchiveView, MonthArchiveView, DayArchiveView, DateDetailView
from datetime import date
from news.models import News

sqs = SearchQuerySet().models(News)

urlpatterns = patterns('',
    url(r'^$', ArchiveIndexView.as_view(
        date_field = 'pub_date',
        model=News,
        context_object_name="latest_news",),
        ),
    url(r'^(?P<year>\d{4})/$', YearArchiveView.as_view(
        date_field = 'pub_date',
        model=News,
        context_object_name="year_archive",),
        ),
    url(r'^(?P<year>\d{4})/(?P<month>\w{3})/$', MonthArchiveView.as_view(
        date_field = 'pub_date',
        model=News,
        context_object_name="month_archive",),
        ),
    url(r'^(?P<year>\d{4})/(?P<month>\w{3})/(?P<day>\d{2})/$', DayArchiveView.as_view(
        date_field = 'pub_date',
        model=News,
        context_object_name="day_archive",),
        ),
    url(r'^(?P<year>\d{4})/(?P<month>\w{3})/(?P<day>\d{2})/(?P<slug>[-\w]+)/$', DateDetailView.as_view(
        date_field = 'pub_date',
        model=News,
        context_object_name="news_detail",),
        ),
    url(r'^search/$', SearchView(
        template='news/search.html',
        searchqueryset=sqs,
    ), name='haystack_search'),
)

Sorry for the slightly messy code; I tend to clean things up once I’ve got them working. Any help much appreciated.

  • 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-06-17T06:08:29+00:00Added an answer on June 17, 2026 at 6:08 am

    Nowhere here do you name your URLs.

    You can’t reverse news_detail if it hasn’t been defined somewhere.

       url(r'^(?P<year>\d{4})/(?P<month>\w{3})/(?P<day>\d{2})/(?P<slug>[-\w]+)/$',       
          DateDetailView.as_view(
            date_field = 'pub_date',
            model=News,
            context_object_name="news_detail",),
            ),
           name='news_detail'),  #<--- you're missing this
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This is my first project in django and im using photologue for gallery, which
This is my first project that i need to use some database ( using
this is my first python project. I am having issues setting up a project
This is my first applet project and for some reason when I try to
This is the first time I'm creating an open-source project, and I've decided (based
This is my first project in PHP based on the Oops Concept. I am
Newbie to ruby this is my first project I am using the FasterCSV Gem
This is the first project by me which is using MongoDB. I have hosted
This is my first project using Ruby on Rails and I'm working on the
My first project using two different new technologies would be to implement some session

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.