Metadata-Version: 2.1
Name: django_cacheable_model
Version: 1.0.1b0
Summary: A cacheable Django model
Home-page: https://github.com/harisankar-krishna-swamy/django_cacheable_model.git
Author: Harisankar Krishna Swamy
Author-email: harisankar.krishna@outlook.com
License: Apache2
Classifier: Programming Language :: Python :: 3
Classifier: License :: OSI Approved :: Apache Software License
Classifier: Operating System :: OS Independent
Requires-Python: >=3.7.4, <4
Description-Content-Type: text/markdown

# django cacheable model
A cacheable model for django.

* A generic way of creating cache keys from Django model fields
* Retrieve django models from cache with field values (cache on the way if cache missed)
* Retrieve all the model instances (suitable for small set of models)

See usage example below

# 1. Github
https://github.com/harisankar-krishna-swamy/django_cacheable_model

# 2. Install
pip install django_cacheable_model

# 3. Usage

See samples in  `example_django_project` views.py and models.py.

### 3.1. Create a model that inherits from CacheableModel
```python
class Question(CacheableModel):
    question_text = models.CharField(max_length=200)
    pub_date = models.DateTimeField('date published')


class Choice(CacheableModel):
    question = models.ForeignKey(Question, on_delete=models.CASCADE)
    choice_text = models.CharField(max_length=200)
    votes = models.IntegerField(default=0)
```

### 3.2. Use cache operations from django_cacheable_model.utils

```python
from django_cacheable_model.utils import all_ins_from_cache, model_ins_from_cache

# Get all instances of model from cache (use for smaller set of models)
context['choices'] = all_ins_from_cache(Choice)

# Get all instances with select_related and order_by
choices = all_ins_from_cache(Choice,
                             select_related=('question',),
                             order_by_fields=('-id',))

# Get a single model
context['choice'] = model_ins_from_cache(Choice, {'id': 5})[-1]
```

# 4. To do
a) Add more tests  
b) Document use of prefetch_related

# 5. License
Apache2 License
