Recently, I made chat service with django channels
. It’s not temporary chat like CS, so I have to save and load all chat logs and messages.
First, I try to use redis
to save those data.
But it’s not that big project, and I want to use django ORM to those data.
I found good library to make multiple table per one model. I want to make multiple tables for Message
model.
architect enhances ORMs with more feature.
Installing
pip install architect
Table partitioning
Which architect
, we can partition sql tables for each model.
Add model
import architect
@architect.install('partition', **options)
class Model(object):
pass
For options, we can use
- type(required) : range, list, etc…
- subtype(required) : range, date, integer, string_firstchars, string_lastchars
- contraint(required)
- column(required)
- db (optional) :
Django
orSQLAlchemy
i.e. if want to divide by ForeignKey
id,
@architect.install('partition', type='range', subtype='integer', constraint='1', column='room_id')
class Message(models.Model):
room = models.ForeignKey(Room, related_name='messages')
message = models.TextField()
Usage
Then we can be accessed via Model.architect.partition
.
also operation with Model.architect.operation
command.
For more information, check official docs
'backend > django' 카테고리의 다른 글
Django: use ckeditor in django - django ckeditor (0) | 2018.05.24 |
---|---|
Django: logout when get for django-allauth (0) | 2018.05.23 |
Django: add extra context to admin changelist view (0) | 2018.05.10 |
Django: multiple choices in django admin list_filter (0) | 2018.05.09 |
Django: custom filter for list_filter in admin (0) | 2018.05.05 |