summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorluxagraf <sng@luxagraf.net>2023-07-26 08:38:56 -0500
committerluxagraf <sng@luxagraf.net>2023-07-26 08:38:56 -0500
commit0a34300e9f3de1d16deae6e7c61786763105f188 (patch)
treefa684782242678251a44fac074b3c8473b15af2a
parent547b4dfe7ffcef5062046180000ff669412b208a (diff)
notes: updated the form to have two buttons and not require a post
-rw-r--r--app/notes/forms.py2
-rw-r--r--app/notes/models.py2
-rw-r--r--app/notes/templates/notes/note_form.html1
-rw-r--r--app/notes/views.py11
4 files changed, 13 insertions, 3 deletions
diff --git a/app/notes/forms.py b/app/notes/forms.py
index 4342b89..f4ca7b9 100644
--- a/app/notes/forms.py
+++ b/app/notes/forms.py
@@ -1,4 +1,5 @@
from django.forms import ModelForm
+from django.forms import ChoiceField
from .models import Note
from posts.models import Post
@@ -10,6 +11,7 @@ class NoteCreateForm(ModelForm):
self.user = user
super(NoteCreateForm,self).__init__(*args,**kwargs)
self.fields['post'].queryset = Post.objects.filter(user=user).order_by("title")
+ self.fields['post'].required = False
def save(self, commit=True):
self.instance.user = self.user
diff --git a/app/notes/models.py b/app/notes/models.py
index e3dd312..6fa3cca 100644
--- a/app/notes/models.py
+++ b/app/notes/models.py
@@ -13,7 +13,7 @@ class Note(models.Model):
url = models.CharField(max_length=400, blank=True, null=True)
body_markdown = models.TextField(blank=True, null=True)
date_created = models.DateTimeField(default=timezone.now)
- post = models.ForeignKey(Post, on_delete=models.CASCADE, null=True)
+ post = models.ForeignKey(Post, on_delete=models.CASCADE, null=True, blank=True)
STATUS = (
(0, 'Call In'),
(1, 'Coming'),
diff --git a/app/notes/templates/notes/note_form.html b/app/notes/templates/notes/note_form.html
index 48ccde1..e360345 100644
--- a/app/notes/templates/notes/note_form.html
+++ b/app/notes/templates/notes/note_form.html
@@ -9,6 +9,7 @@
</fieldset>
<small class="alert">{% if field.errors %}{{field.errors}}{% endif %}</small>
{%endfor%}
+ <input class="btn" type="submit" name="add_new" value="Save and add another" />
<input type="submit" name="save" class="btn" value="Save" />
</form>
</main>
diff --git a/app/notes/views.py b/app/notes/views.py
index 53312ef..fd6aa68 100644
--- a/app/notes/views.py
+++ b/app/notes/views.py
@@ -16,8 +16,15 @@ class NoteCreateView(LoginRequiredMixin, CreateView):
kwargs.update({'user': self.request.user})
return kwargs
- def get_success_url(self):
- return reverse('posts:detail', kwargs={"pk": self.object.post.pk})
+ def get_Success_url(self):
+ if 'add_new' in self.request.POST:
+ return reverse('notes:create')
+ else:
+ if self.object.post:
+ return reverse('posts:detail', kwargs={"pk": self.object.post.pk})
+ else:
+ return reverse('notes:create')
+
class NoteUpdateView(LoginRequiredMixin, UpdateView):