Skip to main content

django-cs-archive

A date-based archiving system (YYYY/MM/DD) for Django applications.

This package wraps Django's powerful generic date views into a plug-and-play solution. It follows the "Convention over Configuration" philosophy: just add a few lines to your settings.py, and you're ready to go.

Features

  • 📅 Full Hierarchy: Year, Month, and Day views.
  • ⚙️ Centralized Configuration: Managed via settings.py, similar to AUTH_USER_MODEL.
  • 🔌 Plug-and-play: No need to write complex views or URL patterns manually.
  • 🐍 Compatibility: Supports Django 3.2+.

Installation

Install via pip:

pip install django-cs-archive

Configuration

This is the most important part. Follow these three simple steps:

1. settings.py

Add the app to your installed apps and define which model you want to archive.

INSTALLED_APPS = [
    # ... other apps
    'django_cs_archive',
]

# REQUIRED: The model to be managed by the archive
# Format: 'app_label.ModelName'
CS_ARCHIVE_MODEL = 'blog.Article' 

# OPTIONAL: The name of the date/datetime field in your model
# Defaults to 'publish_date' if not set.
CS_ARCHIVE_DATE_FIELD = 'pub_date'

# OPTIONAL: Filters to apply to the model queryset.
# Specified as a Python dictionary (or a JSON string representing a dictionary).
CS_ARCHIVE_FILTERS = {
    'status': 'published',
    'is_public': True,
}
# Or as a JSON string:
# CS_ARCHIVE_FILTERS = '{"status": "published", "is_public": true}'

2. urls.py

Include the archive URLs in your project's main URL configuration. You can choose any prefix you like (e.g., news/, archive/, blog/).

from django.urls import path, include

urlpatterns = [
    # ...
    path('archive/', include('django_cs_archive.urls')),
]

3. Prepare your Model (models.py)

Your model (defined in CS_ARCHIVE_MODEL) must satisfy at least two requirements:

  1. Have a Date or DateTime field (matching the name in settings).
  2. Have a Slug field (named slug) to generate unique URLs.

It is highly recommended to add the get_absolute_url method to easily generate links in your templates:

from django.db import models
from django.urls import reverse

class Article(models.Model):
    title = models.CharField(max_length=200)
    slug = models.SlugField(unique_for_date='pub_date') # Important for data integrity
    pub_date = models.DateTimeField()
    content = models.TextField()

    def get_absolute_url(self):
        # Generate the URL 
        return reverse('detail', kwargs={
            'slug': self.slug,
        })

Usage

Once configured, the following URLs will be automatically available (assuming you used the archive/ prefix):

  • /archive/ -> The year list.
  • /archive/2024/ -> All months with articles from 2024.
  • /archive/2024/03/ -> All days with articles March 2024.
  • /archive/2024/03/15/ -> All articles from that specific day.

Customization (Templates)

The package has templates that extend your "base.html" file and uses the {% block content %} block to show the content. To customize the look and feel, create the following files in your project's templates directory:

  • templates/django_cs_archive/archive_year.html
  • templates/django_cs_archive/archive_month.html
  • templates/django_cs_archive/archive_day.html
  • templates/django_cs_archive/archive_detail.html

License

MIT License.

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

django_cs_archive-1.4.0.tar.gz (14.3 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

django_cs_archive-1.4.0-py3-none-any.whl (21.6 kB view details)

Uploaded Python 3

File details

Details for the file django_cs_archive-1.4.0.tar.gz.

File metadata

  • Download URL: django_cs_archive-1.4.0.tar.gz
  • Upload date:
  • Size: 14.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/7.0.0 CPython/3.13.14

File hashes

Hashes for django_cs_archive-1.4.0.tar.gz
Algorithm Hash digest
SHA256 453ccf3d28f7f8d76a1112c501a0b4bed672f79330150a83c0f014791e98c161
MD5 9ef0cb7000ea372c7691517c2c48832d
BLAKE2b-256 29b828d72b4e78134013e51928114a4d9a5d118290db4e87f6bb61c28993e92a

See more details on using hashes here.

Provenance

The following attestation bundles were made for django_cs_archive-1.4.0.tar.gz:

Publisher: python-publish.yml on uloidi/django-cs-archive

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file django_cs_archive-1.4.0-py3-none-any.whl.

File metadata

File hashes

Hashes for django_cs_archive-1.4.0-py3-none-any.whl
Algorithm Hash digest
SHA256 7bf2d07c2a206ed523fc215dd7b293f5ce42aa4bd3906efa01d96c43a635a204
MD5 d77b9e04b46e77a01f77ad021b0fd5ad
BLAKE2b-256 311f11431ed656459ed2751d2a6620edf7a6def3f2b8e17ee85113a98e42ff4d

See more details on using hashes here.

Provenance

The following attestation bundles were made for django_cs_archive-1.4.0-py3-none-any.whl:

Publisher: python-publish.yml on uloidi/django-cs-archive

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Release history Release notifications | RSS feed

1.4.1

2 files

This release

1.4.0 This release

2 files

1.3.0

2 files

1.2.1

2 files

1.2.0

2 files

1.0.0

2 files

0.1.0

2 files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page