Skip to main content
https://travis-ci.org/theatlantic/django-curation.svg?branch=master

django-curation is a django module that provides a model used for curating other model objects and proxying their attributes.

Example

from django.db import models

from curation.models import CuratedItem, CuratedGroup, CuratedItemManager
from curation.fields import CuratedForeignKey

from blog.models import Post

class CuratedPostGroup(CuratedGroup):
    pass

class CuratedPost(CuratedItem):
    formfield_overrides = {
        'custom_title': 'title',
    }
    objects = CuratedItemManager()

    group = models.ForeignKey(CuratedPostGroup, on_delete=models.CASCADE)
    post = curation.fields.CuratedForeignKey(Post)
    custom_title = models.CharField(max_length=255, null=True, blank=True,
        db_column='title')

Testing

tox

Setup:

python3 -m venv venv
. venv/bin/activate
pip install tox

Run all tests:

tox

Run code coverage and render HTML report:

tox -e cov
open htmlcov/index.html

pytest

Setup:

python3 -m venv venv
. venv/bin/activate
pip install pytest pytest-cov pytest-django "Django<2.1"
pip install -e .

Run tests:

python -m pytest

Run code coverage and render HTML report:

python -m pytest --cov-report html --cov-report term --cov=curation

Internals

curation.models.CuratedItem

Abstract class representing an item in a curated group.

In order for a model that extends this class to proxy successfully, it must define a CuratedForeignKey field:

class CuratedPost(CuratedItem):
    post = curation.fields.CuratedForeignKey(Post)

field_overrides = {}

A dict that maps field names in the proxy model (the to=… model in the CuratedForeignKey) to field names in the current model which can override them (provided their value is not None or an empty string).

This takes the form:

field_overrides = {
     'title': 'custom_title',
     'status': 'custom_status',
}

Where custom_title and custom_status are fields in the model extending CuratedItem, and title and status are fields in the proxy model.

primary_id = models.AutoField(primary_key=True, db_column='id')

Custom primary key to prevent conflicts with the proxy model’s primary key.

curation.models.CuratedItemManager

A manager that defines queryset helpers for CuratedItem.

group(<slug>)

Filter the current queryset to rows with curated groups having slug “slug”.

curation.base.CuratedItemModelBase

Overrides ModelBase to check whether a curation.fields.CuratedForeignKey is defined on the model. If not, throw a TypeError.

curation.fields.CuratedForeignKey

A ForeignKey that gets a list of the __dict__ keys and field names of the related model on load. It saves this list to the _proxy_attrs attribute of its parent model’s _meta attribute.

contribute_to_class(<cls>, <name>)

A django built-in that adds attributes to the model class in which it is defined.

This method sets the _curated_proxy_field_name on the _meta attribute of the CuratedForeignKey’s parent model to the field’s name (e.g. “post” in the example at the very beginning of this README).

Release files for django-curation 2.1.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for django-curation 2.1.0
File Size Uploaded
django_curation-2.1.0.tar.gz 27.4 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for django-curation 2.1.0
File Interpreter ABI Platform
django_curation-2.1.0-py2.py3-none-any.whl Python 2, Python 3 none any Details

Total release size: 57.0 kB

Release files / django_curation-2.1.0.tar.gz

Download URL django_curation-2.1.0.tar.gz
Size 27.4 kB
Tags Source
SHA-256 checksum
How to use checksums
a4b3813f0deefa1af96158c072263d32bd80df1f2ccfa47b29591bbe92dbaa47
BLAKE2b-256 checksum
How to use checksums
3ecdf99e5c1f545c392ee4a5b5186a6d8b996455c1368ddebcdfd82962b5fc67
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.12.5

Release files / django_curation-2.1.0-py2.py3-none-any.whl

Download URL django_curation-2.1.0-py2.py3-none-any.whl
Size 29.6 kB
Tags Python 2 Python 3
SHA-256 checksum
How to use checksums
7692cd58404ccf999f6ec22e9aab59857a16ecdb01e138c4c17a6f7e22f3b011
BLAKE2b-256 checksum
How to use checksums
b8e8b3461879fbc12cea76be7907a8a765ac7290d1b44e4a001cfe3f67a1a6cf
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.12.5

Release history Release notifications | RSS feed

This release

2.1.0 This release

2 release files

2.0.2

2 release files

2.0.1

2 release files

1.0.31

2 release 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