Skip to main content

Django: Basic Models Behaviors

Latest Version on PyPI Supported Python versions TravisCI status

Tiny app to provide basic behaviors for django models, like:

  • Timestampable

  • Publishable

  • SoftDeletable

  • Cacheable

Installation

From PyPI:

$ pip install django-basic-models-behaviors

Usage

PublishableModel

Here is an example of Article using PublishableModel:

from basic_models_behaviors import models as behaviors
from django.db import models

class Article(behaviors.PublishableModel):
    title = models.CharField(max_length=255)
    contents = models.TextField()

Then:

>>> article = Article(title='Foo', contents='Lorem lipsum')
>>> article.publish()
>>> article.is_published()
True
>>> article.unpublish()
>>> article.is_published()
False
>>> article.is_not_published()
True

SoftDeletableModel

SoftDeletableModel behavior will add deleted_at field in set the current timestamp instead of delete the object. force_delete() will actually delete the model.

In your models.py:

from basic_models_behaviors import models as behaviors
from django.db import models

class Article(behaviors.SoftDeletableModel):
    title = models.CharField(max_length=255)
    contents = models.TextField()

Then:

>>> from models import Article
>>> article = Article(title='foo', contents='Lorem lipsum')
>>> article.delete()
>>> article.has_been_deleted()
True
>>> article.undelete()
>>> article.has_been_deleted()
False
>>> article.force_delete()

Tests

Run tests:

$ pip install -r tests/requirements.txt
$ py.test --ds=tests.settings tests

Authors

Metadata

Release files for django-basic-models-behaviors 0.6.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-basic-models-behaviors 0.6.0
File Size Uploaded Provenance
django-basic-models-behaviors-0.6.0.tar.gz 7.4 kB Without provenance Details

Release files / django-basic-models-behaviors-0.6.0.tar.gz

Download URL django-basic-models-behaviors-0.6.0.tar.gz
Size 7.4 kB
Tags Source
SHA-256 checksum
How to use checksums
61ebe71c48c6e85d01ceb2b0b6d9e59baea97d1508c9f5f7103ce087384047ef
BLAKE2b-256 checksum
How to use checksums
7b65a0d83bd0a36ffa9203697c312b6624abb5383dabf7635284d7c8fb5f0cba
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Security for django-basic-models-behaviors 0.6.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

0.6.0 This release

1 release file No provenance

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