X-Git-Url: https://git.mdrn.pl/redakcja.git/blobdiff_plain/b2d72160e2a68991c66ea6017b871d7f42c0b29d..1eb24182f3aa52108546f0cacd17e52e54a3a57c:/apps/api/models.py diff --git a/apps/api/models.py b/apps/api/models.py index 71a83623..ac694880 100644 --- a/apps/api/models.py +++ b/apps/api/models.py @@ -1,3 +1,33 @@ from django.db import models # Create your models here. +class PartCache(models.Model): + document_id = models.CharField(max_length=255) + user_id = models.CharField(max_length=64, blank=True) + part_id = models.CharField(max_length=255) + + @classmethod + def update_cache(me, docid, userid, old, new): + old = set(old) + new = set(new) + + related = me.objects.filter(user_id=userid, document_id=docid) + + missing = old.difference(new) + related.filter(part_id__in=missing).delete() + + created = new.difference(old) + + for part in created: + me.objects.create(user_id=userid, document_id=docid, part_id=part) + + + + + + + + + + + \ No newline at end of file