Django or python question about classes

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

Django or python question about classes

youpsla
Hello,
in my code, I like to overrride the form_valid() method in both
CreateView and UpdateView generic class views.

I've put my code in views.py.

class MyCreateView(UpdateView):
    .....
    def form_valid(self, form, **kwargs):
        some code

class MyUpdateView(CreateView):
    .....
    def form_valid(self, form, **kwargs):
        some code

The both form_valid() methods are exactly the same (Only the
dispatch() method differ from both classes).

My question is : is there a way of doing this more in a DRY way ?

Thanks in advance.

Best regards

Alain

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To post to this group, send email to [hidden email].
To unsubscribe from this group, send email to [hidden email].
For more options, visit this group at http://groups.google.com/group/django-users?hl=en.

Reply | Threaded
Open this post in threaded view
|

Re: Django or python question about classes

Tom Evans-3
On Mon, Nov 28, 2011 at 4:07 PM, youpsla <[hidden email]> wrote:

> Hello,
> in my code, I like to overrride the form_valid() method in both
> CreateView and UpdateView generic class views.
>
> I've put my code in views.py.
>
> class MyCreateView(UpdateView):
>    .....
>    def form_valid(self, form, **kwargs):
>        some code
>
> class MyUpdateView(CreateView):
>    .....
>    def form_valid(self, form, **kwargs):
>        some code
>
> The both form_valid() methods are exactly the same (Only the
> dispatch() method differ from both classes).
>
> My question is : is there a way of doing this more in a DRY way ?
>
> Thanks in advance.
>
> Best regards
>
> Alain
>

http://stackoverflow.com/questions/533631/what-is-a-mixin-and-why-are-they-useful

Cheers

Tom

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To post to this group, send email to [hidden email].
To unsubscribe from this group, send email to [hidden email].
For more options, visit this group at http://groups.google.com/group/django-users?hl=en.

Reply | Threaded
Open this post in threaded view
|

Re: Django or python question about classes

youpsla
Thanks for the link Tom.

I'll read that in details later (it's a little bit complicated) an for
my POC I'll just use a not DRY method !!! :-)

Regards

Youpsla

On 28 nov, 17:16, Tom Evans <[hidden email]> wrote:

> On Mon, Nov 28, 2011 at 4:07 PM, youpsla <[hidden email]> wrote:
> > Hello,
> > in my code, I like to overrride the form_valid() method in both
> > CreateView and UpdateView generic class views.
>
> > I've put my code in views.py.
>
> > class MyCreateView(UpdateView):
> >    .....
> >    def form_valid(self, form, **kwargs):
> >        some code
>
> > class MyUpdateView(CreateView):
> >    .....
> >    def form_valid(self, form, **kwargs):
> >        some code
>
> > The both form_valid() methods are exactly the same (Only the
> > dispatch() method differ from both classes).
>
> > My question is : is there a way of doing this more in a DRY way ?
>
> > Thanks in advance.
>
> > Best regards
>
> > Alain
>
> http://stackoverflow.com/questions/533631/what-is-a-mixin-and-why-are...
>
> Cheers
>
> Tom

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To post to this group, send email to [hidden email].
To unsubscribe from this group, send email to [hidden email].
For more options, visit this group at http://groups.google.com/group/django-users?hl=en.