fix unique between attachment and topic
This commit is contained in:
@@ -86,7 +86,7 @@ class Topic(models.Model):
|
|||||||
class Attachment(models.Model):
|
class Attachment(models.Model):
|
||||||
title = models.CharField(verbose_name="Titel", max_length=128)
|
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)
|
slug = models.SlugField(max_length=10)
|
||||||
|
|
||||||
description = models.TextField(null=True, blank=True)
|
description = models.TextField(null=True, blank=True)
|
||||||
|
|||||||
@@ -156,7 +156,7 @@ class TopicCreateView(LoginRequiredMixin, CreateView):
|
|||||||
|
|
||||||
def get_context_data(self, **kwargs):
|
def get_context_data(self, **kwargs):
|
||||||
context = super().get_context_data(**kwargs)
|
context = super().get_context_data(**kwargs)
|
||||||
|
|
||||||
topic_group = TopicGroup.objects.filter(slug=self.slug).first()
|
topic_group = TopicGroup.objects.filter(slug=self.slug).first()
|
||||||
context["topic_group"] = topic_group
|
context["topic_group"] = topic_group
|
||||||
|
|
||||||
@@ -165,6 +165,7 @@ class TopicCreateView(LoginRequiredMixin, CreateView):
|
|||||||
def get_initial(self):
|
def get_initial(self):
|
||||||
self.slug = self.kwargs.get("topic_group")
|
self.slug = self.kwargs.get("topic_group")
|
||||||
|
|
||||||
|
|
||||||
class TopicUpdateView(LoginRequiredMixin, UpdateView):
|
class TopicUpdateView(LoginRequiredMixin, UpdateView):
|
||||||
model = Topic
|
model = Topic
|
||||||
template_name = "intern/topic/topic_update.html"
|
template_name = "intern/topic/topic_update.html"
|
||||||
@@ -175,7 +176,7 @@ class TopicUpdateView(LoginRequiredMixin, UpdateView):
|
|||||||
def get_context_data(self, **kwargs):
|
def get_context_data(self, **kwargs):
|
||||||
context = super().get_context_data(**kwargs)
|
context = super().get_context_data(**kwargs)
|
||||||
context["slug"] = self.slug
|
context["slug"] = self.slug
|
||||||
|
|
||||||
topic = Topic.objects.filter(slug=self.slug).first()
|
topic = Topic.objects.filter(slug=self.slug).first()
|
||||||
context["topic"] = topic
|
context["topic"] = topic
|
||||||
|
|
||||||
@@ -202,9 +203,9 @@ class AttachmentCreateView(LoginRequiredMixin, CreateView):
|
|||||||
def get_context_data(self, **kwargs):
|
def get_context_data(self, **kwargs):
|
||||||
context = super().get_context_data(**kwargs)
|
context = super().get_context_data(**kwargs)
|
||||||
context["slug"] = self.slug
|
context["slug"] = self.slug
|
||||||
|
|
||||||
topic = Topic.objects.filter(slug=self.slug).first()
|
topic = Topic.objects.filter(slug=self.slug).first()
|
||||||
context["topic"]= topic
|
context["topic"] = topic
|
||||||
|
|
||||||
return context
|
return context
|
||||||
|
|
||||||
@@ -232,7 +233,9 @@ class AttachmentUpdateView(LoginRequiredMixin, UpdateView):
|
|||||||
context["topic_slug"] = self.topic_slug
|
context["topic_slug"] = self.topic_slug
|
||||||
context["slug"] = self.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
|
context["attachment"] = attachment
|
||||||
return context
|
return context
|
||||||
|
|
||||||
@@ -266,7 +269,9 @@ class EtherpadCreateView(LoginRequiredMixin, CreateView):
|
|||||||
context["topic_slug"] = self.topic_slug
|
context["topic_slug"] = self.topic_slug
|
||||||
context["slug"] = self.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
|
context["attachment"] = attachment
|
||||||
|
|
||||||
return context
|
return context
|
||||||
@@ -298,7 +303,9 @@ class FileUploadCreateView(LoginRequiredMixin, CreateView):
|
|||||||
context["topic_slug"] = self.topic_slug
|
context["topic_slug"] = self.topic_slug
|
||||||
context["slug"] = self.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
|
context["attachment"] = attachment
|
||||||
|
|
||||||
return context
|
return context
|
||||||
|
|||||||
Reference in New Issue
Block a user