##// END OF EJS Templates
Update tag threads' tags when the tag's parent is changed
neko259 -
r1471:cdc57c47 default
parent child Browse files
Show More
@@ -34,6 +34,11 b' class TagAdmin(admin.ModelAdmin):'
34 def display_children(self, obj: Tag):
34 def display_children(self, obj: Tag):
35 return ', '.join([str(child) for child in obj.get_children().all()])
35 return ', '.join([str(child) for child in obj.get_children().all()])
36
36
37 def save_model(self, request, obj, form, change):
38 super().save_model(request, obj, form, change)
39 for thread in obj.get_threads().all():
40 thread.refresh_tags()
41
37 list_display = ('name', 'thread_count', 'display_children')
42 list_display = ('name', 'thread_count', 'display_children')
38 search_fields = ('name',)
43 search_fields = ('name',)
39
44
@@ -59,11 +64,7 b' class ThreadAdmin(admin.ModelAdmin):'
59 # Save parent tags when editing tags
64 # Save parent tags when editing tags
60 def save_related(self, request, form, formsets, change):
65 def save_related(self, request, form, formsets, change):
61 super().save_related(request, form, formsets, change)
66 super().save_related(request, form, formsets, change)
62 obj = form.instance
67 form.instance.refresh_tags()
63 for tag in obj.get_tags().all():
64 parents = tag.get_all_parents()
65 if len(parents) > 0:
66 obj.tags.add(*parents)
67
68
68 list_display = ('id', 'op', 'title', 'reply_count', 'status', 'ip',
69 list_display = ('id', 'op', 'title', 'reply_count', 'status', 'ip',
69 'display_tags')
70 'display_tags')
@@ -3,7 +3,7 b' from adjacent import Client'
3
3
4 from django.db.models import Count, Sum, QuerySet, Q
4 from django.db.models import Count, Sum, QuerySet, Q
5 from django.utils import timezone
5 from django.utils import timezone
6 from django.db import models
6 from django.db import models, transaction
7
7
8 from boards.models import STATUS_BUMPLIMIT, STATUS_ACTIVE, STATUS_ARCHIVE
8 from boards.models import STATUS_BUMPLIMIT, STATUS_ACTIVE, STATUS_ARCHIVE
9
9
@@ -270,3 +270,12 b' class Thread(models.Model):'
270
270
271 def is_monochrome(self):
271 def is_monochrome(self):
272 return self.monochrome
272 return self.monochrome
273
274 # If tags have parent, add them to the tag list
275 @transaction.atomic
276 def refresh_tags(self):
277 for tag in self.get_tags().all():
278 parents = tag.get_all_parents()
279 if len(parents) > 0:
280 self.tags.add(*parents)
281
General Comments 0
You need to be logged in to leave comments. Login now