On Thu, Mar 20, 2014 at 10:12 AM, sashank reddy <preetamsashankre...@gmail.com> wrote: > Hi Tom, > > I have not understood what you have said. Shouldn't choice_desig be called > every time I instantiate it in the view with the form = New_user_form(). I > thought I was creating an object of New_user_form every time I do that.
This is pretty basic python, the function is run when python interprets the class. Eg, class Foo(object): some_var = 'this is a string'.split() The string is split only once, when the class Foo is parsed by python, not whenever an instance of Foo is instantiated. Things that happen when an instance is instantiated are contained in the __init__ method. Although the some_var looks like it is just declaring a class attribute, it is actually just running code in the scope of the class, and as such you can write almost any code there (contrast with definition of class variables in java). Eg this is perfectly valid: class Foo(object): some_var = 'this is a string'.split() some_var = some_var[1:] some_var.sort() Cheers Tom -- 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/CAFHbX1JiOB60zL9kkgb6pbjAHpkRKs%2B5onFzS27ptgP_m9mLXA%40mail.gmail.com. For more options, visit https://groups.google.com/d/optout.