I double checked, this view is unique. here's the whole process by the way.
from a detail page, there is a link that redirects to a create note page. also, the id of the parent object. <a href="{% url 'file_status:note_create_param' object.pk %}" class="badge badge-secondary">Create note</a> then on my url.py, I have two paths pointing to the same view class. one has no parameter, the other has a parameter which I will be using. path('note_create/', views.NoteCreate.as_view(), name='note_create'), path('note_create_param/<int:file_id>/', views.NoteCreate.as_view(), name= 'note_create_param'), # this is what I'm using here's my view class NoteCreate(CreateView): login_url = 'login' model = Note form_class = NoteForm success_url = reverse_lazy('file_status:list') def get_initial(self): print('at get intitial method') return None maybe I'll start another crud cookie cutter project to see if the get initial method will work on that. On Wednesday, December 12, 2018 at 10:39:34 PM UTC+8, Matthew Pava wrote: > > Fascinating. It looks normal, though login_url is not a member of > CreateView. > > Do you perhaps have another class defined with the same name? > > Especially since you do have other class-based views, you must know what > you’re doing. > > > > *From:* django...@googlegroups.com <javascript:> [mailto: > django...@googlegroups.com <javascript:>] *On Behalf Of *Simon A > *Sent:* Tuesday, December 11, 2018 10:32 PM > *To:* Django users > *Subject:* Re: function get_form_kwargs() not being called > > > > I identified that a more efficient way of doing this would be to call the > get initial method but for some reason it doesn't seem to trigger the > function that I'm trying to overriede. > > > > *class NoteCreate(CreateView):* > > * login_url = 'login'* > > * model = Note* > > * form_class = NoteForm* > > * success_url = reverse_lazy('file_status:list')* > > > > * def get_initial(self):* > > * print(self.kwargs['file_id'])* > > * print('in get initial')* > > * initial = super(NoteCreate, self).get_initial()* > > * initial['file'] = 2* > > * return initial* > > > > Please help me understand. this is really getting frustrating:( > > > > For this one, the text in get initial does not get printed. > > > > What works though is when I don't use Class based view. But I still would > like to make it work using class based views since my other views are class > based. > > > On Monday, December 10, 2018 at 8:47:28 PM UTC+8, Simon A wrote: > > I'm trying to pass a parameter from a redirect to the CreateView and to > the form. > > I have no problem retrieving the value from the redirect to the CreateView. > > But my issue is when trying get the value to the form. I'm overriding > get_form_kwargs function of my CreateView but when I try to do operations > from that function, I'm not able to get any result. I tried to do a print > but the print won't display anything. > > > > *class NoteCreate(LoginRequiredMixin, CreateView):* > > * login_url = 'login'* > > * model = Note* > > * form_class = NoteForm* > > * success_url = reverse_lazy('note:list')* > > > > * def get_form_kwargs(self):* > > * kwargs = super(NoteCreate, self).get_form_kwargs()* > > * kwargs.update({'file_id' : self.kwargs['file_id']})* > > * print("im alivveeeeeeeEeeeeeeeeeeeee!")* > > * return kwargs* > > the print statement doesn't seem to be working. It does not show anything > in the console. > > I'm able to render the form with no errors in the console. > > -- > You received this message because you are subscribed to the Google Groups > "Django users" group. > To unsubscribe from this group and stop receiving emails from it, send an > email to django-users...@googlegroups.com <javascript:>. > To post to this group, send email to djang...@googlegroups.com > <javascript:>. > Visit this group at https://groups.google.com/group/django-users. > To view this discussion on the web visit > https://groups.google.com/d/msgid/django-users/ddf41020-5e47-4b82-b766-04df52522152%40googlegroups.com > > <https://groups.google.com/d/msgid/django-users/ddf41020-5e47-4b82-b766-04df52522152%40googlegroups.com?utm_medium=email&utm_source=footer> > . > For more options, visit https://groups.google.com/d/optout. > -- You received this message because you are subscribed to the Google Groups "Django users" group. To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscr...@googlegroups.com. To post to this group, send email to django-users@googlegroups.com. Visit this group at https://groups.google.com/group/django-users. To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/fdfdc6a0-90f4-494c-b2e5-08ece5c2401a%40googlegroups.com. For more options, visit https://groups.google.com/d/optout.