fnp
/
wolnelektury.git
/ commitdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
| commitdiff |
tree
raw
|
patch
|
inline
| side by side (from parent 1:
8451143
)
Prevent userlist duplicates
author
Radek Czajka
<rczajka@rczajka.pl>
Wed, 26 Nov 2025 14:10:24 +0000
(15:10 +0100)
committer
Radek Czajka
<rczajka@rczajka.pl>
Wed, 26 Nov 2025 14:10:24 +0000
(15:10 +0100)
src/social/models.py
patch
|
blob
|
history
diff --git
a/src/social/models.py
b/src/social/models.py
index
c41a78f
..
862db4c
100644
(file)
--- a/
src/social/models.py
+++ b/
src/social/models.py
@@
-365,14
+365,23
@@
class UserList(Syncable, models.Model):
return ls.userlistitem_set.filter(deleted=False, book=book).exists()
def append(self, book):
return ls.userlistitem_set.filter(deleted=False, book=book).exists()
def append(self, book):
- # TODO: check for duplicates?
n = now()
n = now()
- item
= self.userlistitem_set.create
(
+ item
s = self.userlistitem_set.filter
(
book=book,
book=book,
- order=(self.userlistitem_set.aggregate(m=models.Max('order'))['m'] or 0) + 1,
- updated_at=n,
- reported_timestamp=n,
)
)
+ if items.exists():
+ items.update(
+ deleted=False,
+ reported_timestamp=n,
+ )
+ item = items.first()
+ else:
+ item = self.userlistitem_set.create(
+ book=book,
+ order=(self.userlistitem_set.aggregate(m=models.Max('order'))['m'] or 0) + 1,
+ updated_at=n,
+ reported_timestamp=n,
+ )
book.update_popularity()
return item
book.update_popularity()
return item