Fix serialization
This commit is contained in:
parent
62c9028212
commit
f26c0c6cd8
2 changed files with 21 additions and 9 deletions
|
@ -50,7 +50,8 @@ class Snapshot(models.Model):
|
|||
args = args or self.keys
|
||||
return {
|
||||
key: getattr(self, key)
|
||||
for key in args
|
||||
if key != 'tags' else self.get_tags_str()
|
||||
for key in args
|
||||
}
|
||||
|
||||
def as_link(self) -> Link:
|
||||
|
@ -59,6 +60,13 @@ class Snapshot(models.Model):
|
|||
def as_link_with_details(self) -> Link:
|
||||
from ..index import load_link_details
|
||||
return load_link_details(self.as_link())
|
||||
|
||||
def get_tags_str(self) -> str:
|
||||
tags = ','.join(
|
||||
tag.name
|
||||
for tag in self.tags.all()
|
||||
) if self.tags.all() else ''
|
||||
return tags
|
||||
|
||||
@cached_property
|
||||
def bookmarked(self):
|
||||
|
|
|
@ -86,16 +86,20 @@ def merge_links(a: Link, b: Link) -> Link:
|
|||
)
|
||||
|
||||
# all unique, truthy tags
|
||||
tags_a = []
|
||||
if a.tags:
|
||||
tags_a = a.tags.all()
|
||||
tags_b = []
|
||||
if b.tags:
|
||||
tags_b = b.tags.all()
|
||||
#tags_a = []
|
||||
#if a.tags:
|
||||
# tags_a = a.tags.all()
|
||||
#tags_b = []
|
||||
#if b.tags:
|
||||
# tags_b = b.tags.all()
|
||||
|
||||
#tags_set = (
|
||||
# set(tag.name.strip() for tag in tags_a)
|
||||
# | set(tag.name.strip() for tag in tags_b)
|
||||
#)
|
||||
tags_set = (
|
||||
set(tag.name.strip() for tag in tags_a)
|
||||
| set(tag.name.strip() for tag in tags_b)
|
||||
set(tag.strip() for tag in (a.tags or '').split(','))
|
||||
| set(tag.strip() for tag in (b.tags or '').split(','))
|
||||
)
|
||||
tags = ','.join(tags_set) or None
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue