2014年1月22日 星期三

[python][django] django forms super


在使用 django forms 時,有看到幾個django中super的用法,查了一些相關資料。


It’s important to remember to call the superclass method – that’s thatsuper(Blog, self).save(*args, **kwargs) business – to ensure that the object still gets saved into the database. If you forget to call the superclass method, the default behavior won’t happen and the database won’t get touched.



順帶查了 *args, **kwargs

It’s also important that you pass through the arguments that can be passed to the model method – that’s what the *args, **kwargs bit does. Django will, from time to time, extend the capabilities of built-in model methods, adding new arguments. If you use *args, **kwargs in your method definitions, you are guaranteed that your code will automatically support those arguments when they are added.


Models | Django documentation | Django
https://docs.djangoproject.com/en/1.5/topics/db/models/
Programmer blog: Python super() method and class inheritance
http://garmoncheg.blogspot.tw/2012/06/python-super-method-and-class.html
Understanding Python’s ‘super’ | These are Dark Times, Lad
http://blog.timvalenta.com/2009/02/understanding-pythons-super/

沒有留言:

張貼留言