1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
|
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']
class NoteEditForm(ModelForm):
def __init__(self,*args,**kwargs):
user = kwargs.pop('user')
self.user = user
super(NoteEditForm,self).__init__(*args,**kwargs)
self.fields['post'].queryset = Post.objects.all().order_by("title")
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', 'status', 'plan']
|