summaryrefslogtreecommitdiff
path: root/app/notes/forms.py
blob: f4ca7b9ef1d021137ff8b66408836f4ad61d6e38 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
from django.forms import ModelForm
from django.forms import ChoiceField

from .models import Note
from posts.models import Post

class NoteCreateForm(ModelForm):

    def __init__(self,*args,**kwargs):
        user = kwargs.pop('user')
        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
        return super().save(commit=commit)

    class Meta:
        model = Note 
        fields = ['title', 'url', 'body_markdown', 'post']