In memory models for Django, store in memory, query with instance.attribute
Project description
## Introduce
For performance critical fields and models, and don't want to lose the convenience of getting them like attributes.
You can adding user page view by `user.statistics.visits += 1` and get the value by `user.statistics.visits.value
`
## Backends
- redis
- ssdb
## Install
`pip install django-in-memory-models`
## Example
```
from in_memory.ssdb.fields import IntegerField
#from in_memory.redis.fields import IntegerField
# InMemoryModel do not create tables when migrating.
# You can add fields to django.db.models.Model directly.
class IMAccountStatistics(InMemoryModel):
user = InMemoryOneToOneKey(User, related_name='total_statics')
total_subscription = IntegerField()
@classmethod
def get_by_user(cls, pk):
instance = cls(user_id=pk)
return instance
s = User.objects.first().total_statics
print(s)
print(s.user)
print(s.total_subscription.value)
s.total_subscription += 1
print(s.total_subscription.value)
```
Output
```
IMAccountStatistics object
oldcai
0
1
```
## TODO
- Django system cache backend
For performance critical fields and models, and don't want to lose the convenience of getting them like attributes.
You can adding user page view by `user.statistics.visits += 1` and get the value by `user.statistics.visits.value
`
## Backends
- redis
- ssdb
## Install
`pip install django-in-memory-models`
## Example
```
from in_memory.ssdb.fields import IntegerField
#from in_memory.redis.fields import IntegerField
# InMemoryModel do not create tables when migrating.
# You can add fields to django.db.models.Model directly.
class IMAccountStatistics(InMemoryModel):
user = InMemoryOneToOneKey(User, related_name='total_statics')
total_subscription = IntegerField()
@classmethod
def get_by_user(cls, pk):
instance = cls(user_id=pk)
return instance
s = User.objects.first().total_statics
print(s)
print(s.user)
print(s.total_subscription.value)
s.total_subscription += 1
print(s.total_subscription.value)
```
Output
```
IMAccountStatistics object
oldcai
0
1
```
## TODO
- Django system cache backend
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Close
Hashes for django-in-memory-models-1.0.2.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | 5578d5374bb1eca711da7d25f846b1c5a236146518acd7669fe0fd807666c745 |
|
MD5 | 749fabdfda4c193ea71d75d0abb39e3c |
|
BLAKE2b-256 | 87cd94fd47516f2c69e12b4b1044e6892ba7f851cb1b869ed4260453463dbac2 |
Close
Hashes for django_in_memory_models-1.0.2-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | ea91cd333fc5fb8158568b5d95152e7909168105eb16228d583f4d942ca02601 |
|
MD5 | fcfae7b6e7ec3953090df81adeb4023e |
|
BLAKE2b-256 | b67078b99fb76b9ca7b80d56b831370d91b8ed3fb776f669166d153589a3df99 |