fix unique between attachment and topic
This commit is contained in:
@@ -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)
|
||||
|
||||
@@ -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"
|
||||
@@ -204,7 +205,7 @@ class AttachmentCreateView(LoginRequiredMixin, CreateView):
|
||||
context["slug"] = self.slug
|
||||
|
||||
topic = Topic.objects.filter(slug=self.slug).first()
|
||||
context["topic"]= topic
|
||||
context["topic"] = topic
|
||||
|
||||
return context
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user