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']