Tiny app to provide basic behaviors for django models.
Project description
django-basic-models-behaviors is a tiny app to provide basic behaviors like:
Timestampable
Publishable
SoftDeletable
Cacheable
Installation
Ok, so far: you’re crazy! But here is the way you can install this app:
$ 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:
$ cd tests && python manage.py test
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Close
Hashes for django-basic-models-behaviors-0.5.0.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | b2fc7579b70fe19ccd84ce551b3c7a4a1a20fd909487871247f0e6492afda162 |
|
MD5 | d95a1e96adc0d4d1cf5ab43ee9958cd7 |
|
BLAKE2b-256 | ee722d33ba701067fe2e8d5a16f5ed40d1223e6c7b53ea851e13f3b0daf117de |