On Jun 2, 11:31 pm, Luke Plant <l.plant...@cantab.net> wrote: > On Tuesday 01 June 2010 11:43:30 henning.schroe...@gmail.com wrote: > > > On May 30, 7:24 am, Waldemar Kornewald <wkornew...@gmail.com> wrote: > > > Maybe I missed something, but why don't you use __new__ instead > > > of copying the instance? > > > Here is an example where I used __new__ for class based views in my > > project: > >http://djangosnippets.org/snippets/2046/ > > No __call__ or as_view is needed with this approach. > > I can easily replace a function with a class without changing the > > url configuration. > > This is an interesting approach. The only downside I can think of at > the moment is that implementing __new__() like that really violates > expectations - Python programmers have a fairly strong expectation > that if you do 'x = SomeClass()', where SomeClass is defined as a > class, then x will be an instance of SomeClass.
Yes, that's indeed not perfect. However, the instance-based approach is not thread-safe, so we'll have to go with a class-based approach. The only alternative, then, is to extend Django's URL handling code to automatically instantiate classes, but then calling a class-based view would require manually instantiating the class. Yes, __new__ does some magic, but it at least solves all other problems. Kind of reminds me of the CAP theorem: no magic, easily callable, thread safe. Pick two. :) Bye, Waldemar Kornewald -- You received this message because you are subscribed to the Google Groups "Django developers" group. To post to this group, send email to django-develop...@googlegroups.com. To unsubscribe from this group, send email to django-developers+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-developers?hl=en.