Re: Using FormMixin with DetailView

2020-09-13 Thread latu...@gmail.com
Hello Abdu,
I haven't used FormViews in years, there have been major Django versions 
released since this was posted, some of the advice here may no longer be 
relevant. Sorry I can't help more.

On Monday, 7 September 2020 at 23:02:45 UTC+1 Abdu-H wrote:

>
> Hello, i realise this is a very old post, but i am trying to implement 
> your code here, but it seems some code are missing, i was able to get a 
> form, but the contents of my detailView isn't showing, what code am i 
> suppose to put here " A view for displaying a single post ". your help will 
> be greatly appreciated.
> Thank you.
> On Tuesday, 28 July 2015 at 12:08:23 UTC+1 latu...@gmail.com wrote:
>
>> Hello James,
>>
>> Following your advice I turned to using CreateView, and now all the 
>> functionality I wanted seems to work fully. As you suggested there is no 
>> need for a form.py using this method. When I got more time I might 
>> investigate further how to make the original approach work for future 
>> reference.  This is the view code:
>>
>> class PostDetailView(BlogMixin,CreateView):
>>
>> """ A view for displaying a single post """
>> template_name = 'post.html'
>>
>> model = Comment
>> fields = ['body','author_name'] 
>> def get_context_data(self, **kwargs):
>> context = super(PostDetailView, self).get_context_data(**kwargs)
>> context['post'] =  Post.objects.get(pk=self.kwargs['pk'])
>> return context
>> 
>> def form_valid(self, form):
>> obj = form.save(commit=False)
>> obj.parent_post = Post.objects.get(pk=self.kwargs['pk'])
>> obj.save()
>>
>>return redirect('post-detail', self.kwargs['pk'])
>>
>>
>>
>>

-- 
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 view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/3676b02e-4b06-452d-8cea-733a070b07d6n%40googlegroups.com.


Re: Using FormMixin with DetailView

2020-09-07 Thread Abdu-H

Hello, i realise this is a very old post, but i am trying to implement your 
code here, but it seems some code are missing, i was able to get a form, 
but the contents of my detailView isn't showing, what code am i suppose to 
put here " A view for displaying a single post ". your help will be greatly 
appreciated.
Thank you.
On Tuesday, 28 July 2015 at 12:08:23 UTC+1 latu...@gmail.com wrote:

> Hello James,
>
> Following your advice I turned to using CreateView, and now all the 
> functionality I wanted seems to work fully. As you suggested there is no 
> need for a form.py using this method. When I got more time I might 
> investigate further how to make the original approach work for future 
> reference.  This is the view code:
>
> class PostDetailView(BlogMixin,CreateView):
>
> """ A view for displaying a single post """
> template_name = 'post.html'
>
> model = Comment
> fields = ['body','author_name'] 
> def get_context_data(self, **kwargs):
> context = super(PostDetailView, self).get_context_data(**kwargs)
> context['post'] =  Post.objects.get(pk=self.kwargs['pk'])
> return context
> 
> def form_valid(self, form):
> obj = form.save(commit=False)
> obj.parent_post = Post.objects.get(pk=self.kwargs['pk'])
> obj.save()
>
>return redirect('post-detail', self.kwargs['pk'])
>
>
>
>

-- 
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 view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/29f08e84-de56-4e59-b388-fa895e9f868en%40googlegroups.com.


Re: Hello, everybody! I've tried using FormMixin with DetailView and I get error 405 on post method. Can anybody help me? Thanks a lot.

2019-08-23 Thread Catalina Popescu
I'm afraid not. Popescu is a very common first name here.
But your help depends on that presumed relation? ;) Joking.


On Fri, Aug 23, 2019 at 2:19 PM Mehmet Demirkaya 
wrote:

> Do have relation with Mr Popescu from Romanian Central (National) Bank?
>
> On Fri, 23 Aug 2019 at 09:58, Catalina Popescu <
> catalina.t.pope...@gmail.com> wrote:
>
>> Morning, James
>>
>> The browser just throws HTTP ERROR 405.
>> In CMD:
>> Method Not Allowed (POST): books/book/10/
>> Method Not Allowed: books/book/10/
>> "POST /book/book/10/ HTTP/1.1" 405.0
>>
>>
>> On Friday, August 23, 2019 at 12:28:27 AM UTC+3, James Schneider wrote:
>>
>>> Post the full error message and/or traceback reported by the server when
>>> the error occurs.
>>>
>>> -James
>>>
>>> On Thu, Aug 22, 2019, 12:31 PM Catalina Popescu 
>>> wrote:
>>>
 views.py

 class BookDisplay(DetailView):
 model = Book
 template_name = 'books/book_detail.html'

 def get_context_data(self, **kwargs):
 context = super().get_context_data(**kwargs)
 context['form'] = WishBookForm()
 return context

 class WishBook(SingleObjectMixin, FormView):
 form_class = WishBookForm()
 template_name = 'books/book_detail.html'
 model = Status

 def post(self, request):
 if not request.user.is_authenticated:
 return HttpResponseForbidden()
 self.object = self.get_object()
 return super().post(request)

 def get_success_url(self):
 return reverse('books/book_detail', kwargs = {'pk':
 self.object.pk})


 class BookDetail(View):
 def get(self, request):
 view = BookDisplay.as_view()
 return view(request)

 def post(self, request):
 view = WishBook.as_view()
 return view(request)

 forms.py

 class WishBookForm(forms.Form):
 status = forms.ChoiceField(choices=Status.GIVEAWAY_STATUS[:2],
 initial='Cu chef de ducă')


 --
 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...@googlegroups.com.
 To view this discussion on the web visit
 https://groups.google.com/d/msgid/django-users/231fd7dc-3bf2-465c-993b-c476b0ca4dc1%40googlegroups.com
 
 .

>>> --
>> 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 view this discussion on the web visit
>> https://groups.google.com/d/msgid/django-users/31cab945-367f-448c-97fd-56e90f63bb3d%40googlegroups.com
>> 
>> .
>>
>
>
> --
> Mehmet Demirkaya
> +90 505 423 11 80
>
> --
> 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 view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/CACov0_fxDD9CpPb3%2BWydOFS%2B%2Bq%2Bf5Dp8X9wXzQj7yvCty%3DrhwA%40mail.gmail.com
> 
> .
>

-- 
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 view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CAEMudUOyYs5CfnFwPM0P7ZNbcyG7vxzL%3Djap6Z1VbgthDfEbpg%40mail.gmail.com.


Re: Hello, everybody! I've tried using FormMixin with DetailView and I get error 405 on post method. Can anybody help me? Thanks a lot.

2019-08-23 Thread Mehmet Demirkaya
Do have relation with Mr Popescu from Romanian Central (National) Bank?

On Fri, 23 Aug 2019 at 09:58, Catalina Popescu 
wrote:

> Morning, James
>
> The browser just throws HTTP ERROR 405.
> In CMD:
> Method Not Allowed (POST): books/book/10/
> Method Not Allowed: books/book/10/
> "POST /book/book/10/ HTTP/1.1" 405.0
>
>
> On Friday, August 23, 2019 at 12:28:27 AM UTC+3, James Schneider wrote:
>
>> Post the full error message and/or traceback reported by the server when
>> the error occurs.
>>
>> -James
>>
>> On Thu, Aug 22, 2019, 12:31 PM Catalina Popescu 
>> wrote:
>>
>>> views.py
>>>
>>> class BookDisplay(DetailView):
>>> model = Book
>>> template_name = 'books/book_detail.html'
>>>
>>> def get_context_data(self, **kwargs):
>>> context = super().get_context_data(**kwargs)
>>> context['form'] = WishBookForm()
>>> return context
>>>
>>> class WishBook(SingleObjectMixin, FormView):
>>> form_class = WishBookForm()
>>> template_name = 'books/book_detail.html'
>>> model = Status
>>>
>>> def post(self, request):
>>> if not request.user.is_authenticated:
>>> return HttpResponseForbidden()
>>> self.object = self.get_object()
>>> return super().post(request)
>>>
>>> def get_success_url(self):
>>> return reverse('books/book_detail', kwargs = {'pk':
>>> self.object.pk})
>>>
>>>
>>> class BookDetail(View):
>>> def get(self, request):
>>> view = BookDisplay.as_view()
>>> return view(request)
>>>
>>> def post(self, request):
>>> view = WishBook.as_view()
>>> return view(request)
>>>
>>> forms.py
>>>
>>> class WishBookForm(forms.Form):
>>> status = forms.ChoiceField(choices=Status.GIVEAWAY_STATUS[:2],
>>> initial='Cu chef de ducă')
>>>
>>>
>>> --
>>> 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...@googlegroups.com.
>>> To view this discussion on the web visit
>>> https://groups.google.com/d/msgid/django-users/231fd7dc-3bf2-465c-993b-c476b0ca4dc1%40googlegroups.com
>>> 
>>> .
>>>
>> --
> 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 view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/31cab945-367f-448c-97fd-56e90f63bb3d%40googlegroups.com
> 
> .
>


-- 
Mehmet Demirkaya
+90 505 423 11 80

-- 
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 view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CACov0_fxDD9CpPb3%2BWydOFS%2B%2Bq%2Bf5Dp8X9wXzQj7yvCty%3DrhwA%40mail.gmail.com.


Re: Hello, everybody! I've tried using FormMixin with DetailView and I get error 405 on post method. Can anybody help me? Thanks a lot.

2019-08-23 Thread Catalina Popescu
Morning, James

The browser just throws HTTP ERROR 405. 
In CMD: 
Method Not Allowed (POST): books/book/10/
Method Not Allowed: books/book/10/
"POST /book/book/10/ HTTP/1.1" 405.0


On Friday, August 23, 2019 at 12:28:27 AM UTC+3, James Schneider wrote:

> Post the full error message and/or traceback reported by the server when 
> the error occurs.
>
> -James
>
> On Thu, Aug 22, 2019, 12:31 PM Catalina Popescu  > wrote:
>
>> views.py
>>
>> class BookDisplay(DetailView):
>> model = Book
>> template_name = 'books/book_detail.html'
>> 
>> def get_context_data(self, **kwargs):
>> context = super().get_context_data(**kwargs)
>> context['form'] = WishBookForm()
>> return context
>>
>> class WishBook(SingleObjectMixin, FormView):
>> form_class = WishBookForm()
>> template_name = 'books/book_detail.html'
>> model = Status
>> 
>> def post(self, request):
>> if not request.user.is_authenticated:
>> return HttpResponseForbidden()
>> self.object = self.get_object()
>> return super().post(request)
>> 
>> def get_success_url(self):
>> return reverse('books/book_detail', kwargs = {'pk': 
>> self.object.pk})
>>
>> 
>> class BookDetail(View):
>> def get(self, request):
>> view = BookDisplay.as_view()
>> return view(request)
>> 
>> def post(self, request):
>> view = WishBook.as_view()
>> return view(request)
>>
>> forms.py
>>
>> class WishBookForm(forms.Form):
>> status = forms.ChoiceField(choices=Status.GIVEAWAY_STATUS[:2], 
>> initial='Cu chef de ducă')
>>
>>
>> -- 
>> 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...@googlegroups.com .
>> To view this discussion on the web visit 
>> https://groups.google.com/d/msgid/django-users/231fd7dc-3bf2-465c-993b-c476b0ca4dc1%40googlegroups.com
>>  
>> 
>> .
>>
>

-- 
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 view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/31cab945-367f-448c-97fd-56e90f63bb3d%40googlegroups.com.


Re: Hello, everybody! I've tried using FormMixin with DetailView and I get error 405 on post method. Can anybody help me? Thanks a lot.

2019-08-22 Thread James Schneider
Post the full error message and/or traceback reported by the server when
the error occurs.

-James

On Thu, Aug 22, 2019, 12:31 PM Catalina Popescu <
catalina.t.pope...@gmail.com> wrote:

> views.py
>
> class BookDisplay(DetailView):
> model = Book
> template_name = 'books/book_detail.html'
>
> def get_context_data(self, **kwargs):
> context = super().get_context_data(**kwargs)
> context['form'] = WishBookForm()
> return context
>
> class WishBook(SingleObjectMixin, FormView):
> form_class = WishBookForm()
> template_name = 'books/book_detail.html'
> model = Status
>
> def post(self, request):
> if not request.user.is_authenticated:
> return HttpResponseForbidden()
> self.object = self.get_object()
> return super().post(request)
>
> def get_success_url(self):
> return reverse('books/book_detail', kwargs = {'pk': self.object.pk
> })
>
>
> class BookDetail(View):
> def get(self, request):
> view = BookDisplay.as_view()
> return view(request)
>
> def post(self, request):
> view = WishBook.as_view()
> return view(request)
>
> forms.py
>
> class WishBookForm(forms.Form):
> status = forms.ChoiceField(choices=Status.GIVEAWAY_STATUS[:2],
> initial='Cu chef de ducă')
>
>
> --
> 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 view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/231fd7dc-3bf2-465c-993b-c476b0ca4dc1%40googlegroups.com
> 
> .
>

-- 
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 view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CA%2Be%2BciX1baRiKGuYZZcjdMeDyPpicaiqk9aP2fyLMnQEBFQdDw%40mail.gmail.com.


Hello, everybody! I've tried using FormMixin with DetailView and I get error 405 on post method. Can anybody help me? Thanks a lot.

2019-08-22 Thread Catalina Popescu
views.py

class BookDisplay(DetailView):
model = Book
template_name = 'books/book_detail.html'

def get_context_data(self, **kwargs):
context = super().get_context_data(**kwargs)
context['form'] = WishBookForm()
return context

class WishBook(SingleObjectMixin, FormView):
form_class = WishBookForm()
template_name = 'books/book_detail.html'
model = Status

def post(self, request):
if not request.user.is_authenticated:
return HttpResponseForbidden()
self.object = self.get_object()
return super().post(request)

def get_success_url(self):
return reverse('books/book_detail', kwargs = {'pk': self.object.pk})


class BookDetail(View):
def get(self, request):
view = BookDisplay.as_view()
return view(request)

def post(self, request):
view = WishBook.as_view()
return view(request)

forms.py

class WishBookForm(forms.Form):
status = forms.ChoiceField(choices=Status.GIVEAWAY_STATUS[:2], 
initial='Cu chef de ducă')


-- 
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 view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/231fd7dc-3bf2-465c-993b-c476b0ca4dc1%40googlegroups.com.


Re: Using FormMixin with DetailView

2015-07-28 Thread Ioannis Latousakis
Hello James,

Following your advice I turned to using CreateView, and now all the 
functionality I wanted seems to work fully. As you suggested there is no 
need for a form.py using this method. When I got more time I might 
investigate further how to make the original approach work for future 
reference.  This is the view code:

class PostDetailView(BlogMixin,CreateView):
""" A view for displaying a single post """
template_name = 'post.html'
model = Comment
fields = ['body','author_name'] 
def get_context_data(self, **kwargs):
context = super(PostDetailView, self).get_context_data(**kwargs)
context['post'] =  Post.objects.get(pk=self.kwargs['pk'])
return context

def form_valid(self, form):
obj = form.save(commit=False)
obj.parent_post = Post.objects.get(pk=self.kwargs['pk'])
obj.save()

   return redirect('post-detail', self.kwargs['pk'])



-- 
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 http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/73949be8-34ba-481a-94a7-9c93004fcb31%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Using FormMixin with DetailView

2015-07-28 Thread James Schneider
I've reviewed your code a bit more and I see what you're trying to do, I
think.

With that being said, I'll recant what I said about the CreateView.

Your trouble stems from the fact that FormView by default does not perform
a form.save() operation anywhere (it only validates the form). CreateView
does this in the form_valid() method.

I'm not sure what you are doing with the create_view() method in the form,
but it looks like a pseudo-save method. You probably don't need it, but
that chunk off code looks like it actually belongs in form_valid() on the
view, not on the form.

Look into overriding form_valid() in your view. The example you were/are
looking at is missing the save() functionality, and it states so at the
beginning of the section.

"Again, let’s assume we’re not going to store this in a relational database
but instead in something more esoteric that we won’t worry about here."

I think that the docs are a bit misleading here, since I would expect a
large section like this to at least make reference to something like "#save
code here". Maybe it is in there, hard to tell on my phone.

- James

Are you sure you're using 1.7? Your original error posting begs to differ:

Django Version:1.6.11

The particular portion of docs that you are reading is meant to show how
various mixin's can be used together to address specific edge cases, but
other generic classes exist that are much better suited for what you are
trying to do. Follow the link I posted to see examples.

The only 'tricky' portion of what you are trying to do is to attach the
Comment to the Post, which is easily handled by overriding the form_valid()
method in a CreateView.

You may not even need to define a Model Form.

- James
On Jul 28, 2015 1:39 AM, "Ioannis Latousakis"  wrote:

> Hello James,
>
> The reason I am following this approach is because this is what was
> suggested in the documentation, for the scenario where you need to have a
> form within a DetailsView. Although even when I got my code to be identical
> to the documentation example, I still dont get an object created. Still, on
> form submit, the method get_success_url() of PostComment formview is
> called.  I am currently using django 1.7.
>
> On Tuesday, 28 July 2015 11:32:13 UTC+3, James Schneider wrote:
>>
>> Is there a specific reason you aren't just using CreateView rather than
>> trying to mix in a bunch of classes and trying to roll the post() logic
>> yourself? You can probably cut a very large portion of code out and make
>> this super simple.
>>
>>
>> https://docs.djangoproject.com/en/1.6/topics/class-based-views/generic-editing/#model-forms
>>
>> You should also consider upgrading Django immediately to a newer version,
>> as 1.6 is no longer supported.
>>
>> -James
>> The override is this, I was experimenting with save..
>>
>>
>>> class CommentForm(forms.ModelForm):
>>> class Meta:
>>> model = Comment
>>> exclude = ("parent_post","created_at")
>>>
>>>
>>> def create_view(request, **kwargs):
>>> print "IN VIEW"
>>> if request.method == "POST":
>>> parent_fk = self.object
>>> print "PARRENT"
>>> print parent_fk
>>> form = CommentForm(request.POST)
>>> if form.is_valid():
>>> new_comment = form.save(commit=False)
>>> new_comment.parent_post = parent_fk
>>> new_comment.save()
>>> return HttpResponseRedirect(request.META.get(
>>> 'HTTP_REFERER'))
>>>
>>>
>>>  --
>> 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.
>> To post to this group, send email to django...@googlegroups.com.
>> Visit this group at http://groups.google.com/group/django-users.
>> To view this discussion on the web visit
>> https://groups.google.com/d/msgid/django-users/6825b838-584c-4e89-bc4e-4a6d0bf81c5f%40googlegroups.com
>> 
>> .
>> 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 http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CA%2Be%2BciV3_aZPWXGEayTWUb_Mt95XjnCom%2B7_2CbiPiyvcJXy5Q%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: Using FormMixin with DetailView

2015-07-28 Thread Ioannis Latousakis
Right.. I miss read the requirements.txt. Im new to django so started from 
a simple app base and building on top. On first look nothing broke when 
upgrading to 1.7. Ill check the docs you posted now.

On Tuesday, 28 July 2015 11:54:55 UTC+3, James Schneider wrote:
>
> Are you sure you're using 1.7? Your original error posting begs to differ:
>
> Django Version:1.6.11
>
> The particular portion of docs that you are reading is meant to show how 
> various mixin's can be used together to address specific edge cases, but 
> other generic classes exist that are much better suited for what you are 
> trying to do. Follow the link I posted to see examples.
>
> The only 'tricky' portion of what you are trying to do is to attach the 
> Comment to the Post, which is easily handled by overriding the form_valid() 
> method in a CreateView.
>
> You may not even need to define a Model Form.
>
> - James
>
>>
>>>  

-- 
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 http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/f1a549fc-adc8-481a-893e-166b2a7a8718%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Using FormMixin with DetailView

2015-07-28 Thread James Schneider
Are you sure you're using 1.7? Your original error posting begs to differ:

Django Version:1.6.11

The particular portion of docs that you are reading is meant to show how
various mixin's can be used together to address specific edge cases, but
other generic classes exist that are much better suited for what you are
trying to do. Follow the link I posted to see examples.

The only 'tricky' portion of what you are trying to do is to attach the
Comment to the Post, which is easily handled by overriding the form_valid()
method in a CreateView.

You may not even need to define a Model Form.

- James
On Jul 28, 2015 1:39 AM, "Ioannis Latousakis"  wrote:

> Hello James,
>
> The reason I am following this approach is because this is what was
> suggested in the documentation, for the scenario where you need to have a
> form within a DetailsView. Although even when I got my code to be identical
> to the documentation example, I still dont get an object created. Still, on
> form submit, the method get_success_url() of PostComment formview is
> called.  I am currently using django 1.7.
>
> On Tuesday, 28 July 2015 11:32:13 UTC+3, James Schneider wrote:
>>
>> Is there a specific reason you aren't just using CreateView rather than
>> trying to mix in a bunch of classes and trying to roll the post() logic
>> yourself? You can probably cut a very large portion of code out and make
>> this super simple.
>>
>>
>> https://docs.djangoproject.com/en/1.6/topics/class-based-views/generic-editing/#model-forms
>>
>> You should also consider upgrading Django immediately to a newer version,
>> as 1.6 is no longer supported.
>>
>> -James
>> The override is this, I was experimenting with save..
>>
>>
>>> class CommentForm(forms.ModelForm):
>>> class Meta:
>>> model = Comment
>>> exclude = ("parent_post","created_at")
>>>
>>>
>>> def create_view(request, **kwargs):
>>> print "IN VIEW"
>>> if request.method == "POST":
>>> parent_fk = self.object
>>> print "PARRENT"
>>> print parent_fk
>>> form = CommentForm(request.POST)
>>> if form.is_valid():
>>> new_comment = form.save(commit=False)
>>> new_comment.parent_post = parent_fk
>>> new_comment.save()
>>> return HttpResponseRedirect(request.META.get(
>>> 'HTTP_REFERER'))
>>>
>>>
>>>  --
>> 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.
>> To post to this group, send email to django...@googlegroups.com.
>> Visit this group at http://groups.google.com/group/django-users.
>> To view this discussion on the web visit
>> https://groups.google.com/d/msgid/django-users/6825b838-584c-4e89-bc4e-4a6d0bf81c5f%40googlegroups.com
>> 
>> .
>> 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 http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CA%2Be%2BciWMvDuH8M4tYFe5HA4h8mefvP7SBSfHDF9GGO952rF3jw%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: Using FormMixin with DetailView

2015-07-28 Thread Ioannis Latousakis
Hello James,

The reason I am following this approach is because this is what was 
suggested in the documentation, for the scenario where you need to have a 
form within a DetailsView. Although even when I got my code to be identical 
to the documentation example, I still dont get an object created. Still, on 
form submit, the method get_success_url() of PostComment formview is 
called.  I am currently using django 1.7. 

On Tuesday, 28 July 2015 11:32:13 UTC+3, James Schneider wrote:
>
> Is there a specific reason you aren't just using CreateView rather than 
> trying to mix in a bunch of classes and trying to roll the post() logic 
> yourself? You can probably cut a very large portion of code out and make 
> this super simple.
>
>
> https://docs.djangoproject.com/en/1.6/topics/class-based-views/generic-editing/#model-forms
>
> You should also consider upgrading Django immediately to a newer version, 
> as 1.6 is no longer supported.
>
> -James
> The override is this, I was experimenting with save..
>
>
>> class CommentForm(forms.ModelForm):
>> class Meta:
>> model = Comment
>> exclude = ("parent_post","created_at")
>>
>>
>> def create_view(request, **kwargs):
>> print "IN VIEW"
>> if request.method == "POST":
>> parent_fk = self.object
>> print "PARRENT"
>> print parent_fk
>> form = CommentForm(request.POST)
>> if form.is_valid():
>> new_comment = form.save(commit=False)
>> new_comment.parent_post = parent_fk
>> new_comment.save()
>> return HttpResponseRedirect(request.META.get(
>> 'HTTP_REFERER'))
>>
>>
>>  -- 
> 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 .
> To post to this group, send email to django...@googlegroups.com 
> .
> Visit this group at http://groups.google.com/group/django-users.
> To view this discussion on the web visit 
> https://groups.google.com/d/msgid/django-users/6825b838-584c-4e89-bc4e-4a6d0bf81c5f%40googlegroups.com
>  
> 
> .
> 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 http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/3ac05d55-4b68-4afa-a00b-65dfd3a4c939%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Using FormMixin with DetailView

2015-07-28 Thread James Schneider
Is there a specific reason you aren't just using CreateView rather than
trying to mix in a bunch of classes and trying to roll the post() logic
yourself? You can probably cut a very large portion of code out and make
this super simple.

https://docs.djangoproject.com/en/1.6/topics/class-based-views/generic-editing/#model-forms

You should also consider upgrading Django immediately to a newer version,
as 1.6 is no longer supported.

-James
The override is this, I was experimenting with save..


> class CommentForm(forms.ModelForm):
> class Meta:
> model = Comment
> exclude = ("parent_post","created_at")
>
>
> def create_view(request, **kwargs):
> print "IN VIEW"
> if request.method == "POST":
> parent_fk = self.object
> print "PARRENT"
> print parent_fk
> form = CommentForm(request.POST)
> if form.is_valid():
> new_comment = form.save(commit=False)
> new_comment.parent_post = parent_fk
> new_comment.save()
> return HttpResponseRedirect(request.META.get(
> 'HTTP_REFERER'))
>
>
>  --
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 http://groups.google.com/group/django-users.
To view this discussion on the web visit
https://groups.google.com/d/msgid/django-users/6825b838-584c-4e89-bc4e-4a6d0bf81c5f%40googlegroups.com

.
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 http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CA%2Be%2BciUFy7tGdtL9jzRd6xXZadWQGKroW%2BKUs%3D71X7h9tZpxtg%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: Using FormMixin with DetailView

2015-07-28 Thread Ioannis Latousakis
The override is this, I was experimenting with save..


> class CommentForm(forms.ModelForm):
> class Meta:
> model = Comment
> exclude = ("parent_post","created_at")
>
>
> def create_view(request, **kwargs):
> print "IN VIEW"
> if request.method == "POST":
> parent_fk = self.object
> print "PARRENT"
> print parent_fk
> form = CommentForm(request.POST)
> if form.is_valid():
> new_comment = form.save(commit=False)
> new_comment.parent_post = parent_fk
> new_comment.save()
> return HttpResponseRedirect(request.META.get(
> 'HTTP_REFERER'))
>
>
>

-- 
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 http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/6825b838-584c-4e89-bc4e-4a6d0bf81c5f%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Using FormMixin with DetailView

2015-07-28 Thread Ioannis Latousakis
Thanks your your response. I have now gone past that problem and the form 
renders, although on submission of the form nothing happens. The 'POST 
-' string is printed, which means I am on the right track, but no new 
object is created. I tried to simplify the comment form (remove the FK and 
the method override) in case there was a problem with that code, but I 
still dont get a comment created. Here is the current state of the code:

class CommentForm(forms.ModelForm):
class Meta:
model = Comment
exclude = ("parent_post","created_at")


def save():
print "IN VIEW"
if request.method == "POST":
parent_fk = self.object
print "PARRENT"
print parent_fk
form = CommentForm(request.POST)
if form.is_valid():
new_comment = form.save(commit=False)
new_comment.parent_post = parent_fk
new_comment.save()
return HttpResponseRedirect(request.META.get('HTTP_REFERER'
))


class PostView(DetailView):
""" A view for displaying a single post """
template_name = 'post.html'
model = Post
def get_context_data(self, **kwargs):
context = super(PostView, self).get_context_data(**kwargs)
context['form'] = CommentForm()
return context

class PostDetailView(View):


def get(self, request, *args, **kwargs):
view = PostView.as_view()
return view(request, *args, **kwargs)


def post(self, request, *args, **kwargs):
view = PostComment.as_view()
return view(request, *args, **kwargs)


class PostComment(  SingleObjectMixin , FormView):
template_name = 'post.html'
form_class = CommentForm
model = Post


def post(self, request, *args, **kwargs):
print "POST "
self.object = self.get_object()
return super(PostComment, self).post(request, *args, **kwargs)


def get_success_url(self):
return reverse('post-detail', kwargs={'pk': self.object.pk})




url(r'^post/(?P[\d]+)/$', views.PostDetailView.as_view(), name=
"post-detail"),



-- 
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 http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/6af1087a-a95e-4eb8-ac5b-68823a45b4ec%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Using FormMixin with DetailView

2015-07-28 Thread Gergely Polonkai
Forgot to add, the full backtrace would be helpful, too. It should be
present on the same error page.
On 28 Jul 2015 08:52, "Gergely Polonkai" <gerg...@polonkai.eu> wrote:

> Hello,
>
> could you show us the relevant part of your urls.py file? I suspect view
> parameters to cause the trouble but I'd like to be sure.
>
> Best,
> Gergely
> On 28 Jul 2015 00:46, "Ioannis Latousakis" <latus...@gmail.com> wrote:
>
>> I am on the exact same situation as the one described in the
>> documentation here:
>> https://docs.djangoproject.com/en/1.7/topics/class-based-views/mixins/#using-formmixin-with-detailview
>>
>>
>> I have followed the documentation but I get the following exception:
>>
>> __init__() takes exactly 1 argument (3 given)
>>
>> Request Method:GETRequest URL:
>> http://localhost:8000/post/5144752345317376/Django Version:1.6.11Exception
>> Type:TypeErrorException Value:
>>
>> __init__() takes exactly 1 argument (3 given)
>>
>> Exception Location:...app/sitepackages/django/core/handlers/base.py in
>> get_response, line 11
>>
>>
>>
>> I think the only location where I might need something different is my
>> urls.py... Here is the complete code:
>>
>>
>> class PostView(BlogMixin,DetailView):
>> """ A view for displaying a single post """
>> template_name = 'post.html'
>> model = Post
>> def get_context_data(self, **kwargs):
>> context = super(PostView, self).get_context_data(**kwargs)
>> context['form'] = CommentForm()
>> return context
>>
>> class PostDetailView(View):
>> print "HERE    "
>>
>>
>> def get(self, request, *args, **kwargs):
>> print "GET    "
>> view = PostView.as_view()
>> return view(request, *args, **kwargs)
>>
>>
>> def post(self, request, *args, **kwargs):
>> print "POST    "
>> view = PostComment.as_view()
>> return view(request, *args, **kwargs)
>>
>>
>> class PostComment(  SingleObjectMixin , FormView):
>> template_name = 'post.html'
>> form_class = CommentForm
>> model = Post
>>
>>
>> def post(self, request, *args, **kwargs):
>> self.object = self.get_object()
>> return super(PostComment, self).post(request, *args, **kwargs)
>>
>>
>> def get_success_url(self):
>> return reverse('post-detail', kwargs={'pk': self.object.pk})
>>
>> class BlogMixin(object):
>> """
>> Basic mixin for all the views. Update the context with additional
>> information that is required across the whole site, typically
>> to render base.html properly
>> """
>> def get_context_data(self, *args, **kwargs):
>> context = super(BlogMixin, self).get_context_data(*args, **kwargs)
>> blog = Blog.get_unique()
>> context.update({
>> 'blog': blog,
>> 'active_user': users.get_current_user(),
>> 'is_admin': users.is_current_user_admin()
>> })
>> return context
>>
>> urls.py:
>> url(r'^post/(?P[\d]+)/$', views.PostDetailView.,
>> name="post-detail"),
>>
>>
>>
>> Before the exception, 'HERE --" is printed, but no GET or POST
>>
>> --
>> 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 http://groups.google.com/group/django-users.
>> To view this discussion on the web visit
>> https://groups.google.com/d/msgid/django-users/299d4e5e-0b69-4627-a1e6-e7f2d1ff9d8d%40googlegroups.com
>> <https://groups.google.com/d/msgid/django-users/299d4e5e-0b69-4627-a1e6-e7f2d1ff9d8d%40googlegroups.com?utm_medium=email_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 http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CACczBUKwyqRuyU0W%2B6oVnt-HUcuPgW00a6wAcZtX5bdOis4TPA%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: Using FormMixin with DetailView

2015-07-28 Thread Gergely Polonkai
Hello,

could you show us the relevant part of your urls.py file? I suspect view
parameters to cause the trouble but I'd like to be sure.

Best,
Gergely
On 28 Jul 2015 00:46, "Ioannis Latousakis" <latus...@gmail.com> wrote:

> I am on the exact same situation as the one described in the documentation
> here:
> https://docs.djangoproject.com/en/1.7/topics/class-based-views/mixins/#using-formmixin-with-detailview
>
>
> I have followed the documentation but I get the following exception:
>
> __init__() takes exactly 1 argument (3 given)
>
> Request Method:GETRequest 
> URL:http://localhost:8000/post/5144752345317376/Django
> Version:1.6.11Exception Type:TypeErrorException Value:
>
> __init__() takes exactly 1 argument (3 given)
>
> Exception Location:...app/sitepackages/django/core/handlers/base.py in
> get_response, line 11
>
>
>
> I think the only location where I might need something different is my
> urls.py... Here is the complete code:
>
>
> class PostView(BlogMixin,DetailView):
> """ A view for displaying a single post """
> template_name = 'post.html'
> model = Post
> def get_context_data(self, **kwargs):
> context = super(PostView, self).get_context_data(**kwargs)
> context['form'] = CommentForm()
> return context
>
> class PostDetailView(View):
> print "HERE    "
>
>
> def get(self, request, *args, **kwargs):
> print "GET    "
> view = PostView.as_view()
> return view(request, *args, **kwargs)
>
>
> def post(self, request, *args, **kwargs):
> print "POST    "
> view = PostComment.as_view()
> return view(request, *args, **kwargs)
>
>
> class PostComment(  SingleObjectMixin , FormView):
> template_name = 'post.html'
> form_class = CommentForm
> model = Post
>
>
> def post(self, request, *args, **kwargs):
> self.object = self.get_object()
> return super(PostComment, self).post(request, *args, **kwargs)
>
>
> def get_success_url(self):
> return reverse('post-detail', kwargs={'pk': self.object.pk})
>
> class BlogMixin(object):
> """
> Basic mixin for all the views. Update the context with additional
> information that is required across the whole site, typically
> to render base.html properly
> """
> def get_context_data(self, *args, **kwargs):
> context = super(BlogMixin, self).get_context_data(*args, **kwargs)
> blog = Blog.get_unique()
> context.update({
> 'blog': blog,
> 'active_user': users.get_current_user(),
> 'is_admin': users.is_current_user_admin()
> })
> return context
>
> urls.py:
> url(r'^post/(?P[\d]+)/$', views.PostDetailView.,
> name="post-detail"),
>
>
>
> Before the exception, 'HERE --" is printed, but no GET or POST
>
> --
> 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 http://groups.google.com/group/django-users.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/299d4e5e-0b69-4627-a1e6-e7f2d1ff9d8d%40googlegroups.com
> <https://groups.google.com/d/msgid/django-users/299d4e5e-0b69-4627-a1e6-e7f2d1ff9d8d%40googlegroups.com?utm_medium=email_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 http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CACczBUL-Kog-%3D04Biv3uKpE8_qNMNt_GxzFH%3Doa_DNMtRxm83g%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Using FormMixin with DetailView

2015-07-27 Thread Ioannis Latousakis
I am on the exact same situation as the one described in the documentation 
here: 
https://docs.djangoproject.com/en/1.7/topics/class-based-views/mixins/#using-formmixin-with-detailview
 

I have followed the documentation but I get the following exception:

__init__() takes exactly 1 argument (3 given)

Request Method:GETRequest 
URL:http://localhost:8000/post/5144752345317376/Django 
Version:1.6.11Exception Type:TypeErrorException Value:

__init__() takes exactly 1 argument (3 given)

Exception Location:...app/sitepackages/django/core/handlers/base.py in 
get_response, line 11



I think the only location where I might need something different is my 
urls.py... Here is the complete code:


class PostView(BlogMixin,DetailView):
""" A view for displaying a single post """
template_name = 'post.html'
model = Post
def get_context_data(self, **kwargs):
context = super(PostView, self).get_context_data(**kwargs)
context['form'] = CommentForm()
return context

class PostDetailView(View):
print "HERE    "


def get(self, request, *args, **kwargs):
print "GET    "
view = PostView.as_view()
return view(request, *args, **kwargs)


def post(self, request, *args, **kwargs):
print "POST    "
view = PostComment.as_view()
return view(request, *args, **kwargs)


class PostComment(  SingleObjectMixin , FormView):
template_name = 'post.html'
form_class = CommentForm
model = Post


def post(self, request, *args, **kwargs):
self.object = self.get_object()
return super(PostComment, self).post(request, *args, **kwargs)


def get_success_url(self):
return reverse('post-detail', kwargs={'pk': self.object.pk})

class BlogMixin(object):
"""
Basic mixin for all the views. Update the context with additional
information that is required across the whole site, typically
to render base.html properly
"""
def get_context_data(self, *args, **kwargs):
context = super(BlogMixin, self).get_context_data(*args, **kwargs)
blog = Blog.get_unique()
context.update({
'blog': blog,
'active_user': users.get_current_user(),
'is_admin': users.is_current_user_admin()
})
return context

urls.py:
url(r'^post/(?P[\d]+)/$', views.PostDetailView., 
name="post-detail"),



Before the exception, 'HERE --" is printed, but no GET or POST

-- 
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 http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/299d4e5e-0b69-4627-a1e6-e7f2d1ff9d8d%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.