diff --git a/fet2020/intern/models.py b/fet2020/intern/models.py index e6cb74ea..42c4b2a3 100644 --- a/fet2020/intern/models.py +++ b/fet2020/intern/models.py @@ -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) diff --git a/fet2020/intern/views.py b/fet2020/intern/views.py index 5756649e..0cc171e9 100644 --- a/fet2020/intern/views.py +++ b/fet2020/intern/views.py @@ -156,7 +156,7 @@ class TopicCreateView(LoginRequiredMixin, CreateView): def get_context_data(self, **kwargs): context = super().get_context_data(**kwargs) - + topic_group = TopicGroup.objects.filter(slug=self.slug).first() context["topic_group"] = topic_group @@ -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" @@ -175,7 +176,7 @@ class TopicUpdateView(LoginRequiredMixin, UpdateView): def get_context_data(self, **kwargs): context = super().get_context_data(**kwargs) context["slug"] = self.slug - + topic = Topic.objects.filter(slug=self.slug).first() context["topic"] = topic @@ -202,9 +203,9 @@ class AttachmentCreateView(LoginRequiredMixin, CreateView): def get_context_data(self, **kwargs): context = super().get_context_data(**kwargs) 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