Skip to main content
## 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 SSDBSortedIntegerField as IntegerField
# from in_memory.redis.fields import RedisSortedIntegerField as IntegerField


# InMemoryModel do not create tables when migrating.
# You can add fields to django.db.models.Model directly.
class AccountStatistics(InMemoryModel):
user = InMemoryOneToOneKey(User, related_name='statistics')
total_subscription = IntegerField(default=0)

@classmethod
def get_by_user(cls, pk):
instance = cls(user_id=pk)
return instance

def __str__(self):
return '<Account Statistics: %s>' % self.user

s = User.objects.first().statistics
s.total_subscription.reset()
print(s.total_subscription.value)
s.total_subscription += 1
print(s.total_subscription.value)
s.total_subscription = 200
print(s.total_subscription.value)
top_users = s.total_subscription.top(1)
print(top_users)
top_user = top_users[0]
print(top_user)
print(top_user.user)
print(top_user.total_subscription.value)
```

Output

```
0
1
200
[<AccountStatistics: <Account Statistics: oldcai>>]
<Account Statistics: oldcai>
oldcai
200
```

## TODO

- Django system cache backend


Release files for django-in-memory-models 1.0.5

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-in-memory-models 1.0.5
File Size Uploaded
django-in-memory-models-1.0.5.tar.gz 12.1 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for django-in-memory-models 1.0.5
File Interpreter ABI Platform
django_in_memory_models-1.0.5-py3-none-any.whl Python 3 none any Details

Total release size: 29.4 kB

Release files / django-in-memory-models-1.0.5.tar.gz

Download URL django-in-memory-models-1.0.5.tar.gz
Size 12.1 kB
Tags Source
SHA-256 checksum
How to use checksums
9773909a6e84341761969773c17011a5e88f13574d2e6999b07bdb6b421a8dcc
BLAKE2b-256 checksum
How to use checksums
487ed8a508e99f6ac2b66ef0ee548134c5a718acd9c8d07243f9234082a29641
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Release files / django_in_memory_models-1.0.5-py3-none-any.whl

Download URL django_in_memory_models-1.0.5-py3-none-any.whl
Size 17.3 kB
Tags Python 3
SHA-256 checksum
How to use checksums
80de4360f7706bbffb8cd813f9b81107fdf976bca460cbf13f4604e88042f665
BLAKE2b-256 checksum
How to use checksums
42562ec13d1e0f1b073913c756659c44c87f53b38f52fd917e0ce471c2d1510b
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Release history Release notifications | RSS feed

This release

1.0.5 This release

2 release files

1.0.4

2 release files

1.0.3

2 release files

1.0.2

2 release files

1.0.1

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