fix unique between attachment and topic

This commit is contained in:
2022-03-21 13:37:13 +00:00
parent 59e0d89521
commit ae4dd55eb7
2 changed files with 15 additions and 8 deletions

View File

@@ -86,7 +86,7 @@ class Topic(models.Model):
class Attachment(models.Model):
title = models.CharField(verbose_name="Titel", max_length=128)
shortterm = models.CharField(max_length=10, unique=True)
shortterm = models.CharField(max_length=10)
slug = models.SlugField(max_length=10)
description = models.TextField(null=True, blank=True)

View File

@@ -165,6 +165,7 @@ class TopicCreateView(LoginRequiredMixin, CreateView):
def get_initial(self):
self.slug = self.kwargs.get("topic_group")
class TopicUpdateView(LoginRequiredMixin, UpdateView):
model = Topic
template_name = "intern/topic/topic_update.html"
@@ -232,7 +233,9 @@ class AttachmentUpdateView(LoginRequiredMixin, UpdateView):
context["topic_slug"] = self.topic_slug
context["slug"] = self.slug
attachment = Attachment.objects.filter(slug=self.slug).first()
attachment = Attachment.objects.filter(
Q(slug=self.slug) & Q(topic__slug=self.topic_slug)
).first()
context["attachment"] = attachment
return context
@@ -266,7 +269,9 @@ class EtherpadCreateView(LoginRequiredMixin, CreateView):
context["topic_slug"] = self.topic_slug
context["slug"] = self.slug
attachment = Attachment.objects.filter(slug=self.slug).first()
attachment = Attachment.objects.filter(
Q(slug=self.slug) & Q(topic__slug=self.topic_slug)
).first()
context["attachment"] = attachment
return context
@@ -298,7 +303,9 @@ class FileUploadCreateView(LoginRequiredMixin, CreateView):
context["topic_slug"] = self.topic_slug
context["slug"] = self.slug
attachment = Attachment.objects.filter(slug=self.kwargs.get("slug")).first()
attachment = Attachment.objects.filter(
Q(slug=self.slug) & Q(topic__slug=self.topic_slug)
).first()
context["attachment"] = attachment
return context