X-Git-Url: https://git.mdrn.pl/redakcja.git/blobdiff_plain/b2d72160e2a68991c66ea6017b871d7f42c0b29d..826d67400c317836cd9dd02bb03b39a390e4514b:/apps/api/models.py diff --git a/apps/api/models.py b/apps/api/models.py index 71a83623..c08f38db 100644 --- a/apps/api/models.py +++ b/apps/api/models.py @@ -1,3 +1,30 @@ 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