Skip to content

Commit

Permalink
trying to get closer to master
Browse files Browse the repository at this point in the history
might need to roll this back
  • Loading branch information
matthewdylan committed May 1, 2024
1 parent d2ff14f commit 5fb153f
Showing 1 changed file with 8 additions and 10 deletions.
18 changes: 8 additions & 10 deletions taggit/managers.py
Original file line number Diff line number Diff line change
Expand Up @@ -291,37 +291,35 @@ def set(self, tags, *, through_defaults=None, **kwargs):
# make sure we're working with a collection of a uniform type
objs = self._to_tag_model_instances(tags, tag_kwargs)

# get the existing tags
old_tags = set(
t.tag
for t in self.through._default_manager.using(db)
# get the existing tag strings
old_tag_strs = set(
self.through._default_manager.using(db)
.filter(**self._lookup_kwargs())
.select_related("tag")
.values_list("tag__name", flat=True)
)

new_objs = []
for obj in objs:
if obj in old_tags:
old_tags.remove(obj)
if obj.name in old_tag_strs:
old_tag_strs.remove(obj.name)
else:
new_objs.append(obj)

self.remove(*old_tags)
self.remove(*old_tag_strs)
self.add(*new_objs, through_defaults=through_defaults, **kwargs)

@require_instance_manager
def remove(self, *tags):
if not tags:
return
tag_objs = self._to_tag_model_instances(tags)

self._remove_prefetched_objects()
db = router.db_for_write(self.through, instance=self.instance)

qs = (
self.through._default_manager.using(db)
.filter(**self._lookup_kwargs())
.filter(tag__in=tag_objs)
.filter(tag__name__in=tags)
)

old_ids = set(qs.values_list("tag_id", flat=True))
Expand Down

0 comments on commit 5fb153f

Please sign in to comment.