ac694880f11c35c8acf1b5240b1cc5b5b9bb201f
[redakcja.git] / apps / api / models.py
1 from django.db import models
2
3 # Create your models here.
4 class PartCache(models.Model):
5     document_id = models.CharField(max_length=255)
6     user_id = models.CharField(max_length=64, blank=True)    
7     part_id = models.CharField(max_length=255)
8
9     @classmethod
10     def update_cache(me, docid, userid, old, new):
11         old = set(old)
12         new = set(new)
13
14         related = me.objects.filter(user_id=userid, document_id=docid)
15
16         missing = old.difference(new)
17         related.filter(part_id__in=missing).delete()
18
19         created = new.difference(old)
20
21         for part in created:
22             me.objects.create(user_id=userid, document_id=docid, part_id=part)
23
24
25             
26         
27
28         
29
30             
31         
32         
33