V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
推荐学习书目
Learn Python the Hard Way
Python Sites
PyPI - Python Package Index
http://diveintopython.org/toc/index.html
Pocoo
值得关注的项目
PyPy
Celery
Jinja2
Read the Docs
gevent
pyenv
virtualenv
Stackless Python
Beautiful Soup
结巴中文分词
Green Unicorn
Sentry
Shovel
Pyflakes
pytest
Python 编程
pep8 Checker
Styles
PEP 8
Google Python Style Guide
Code Style from The Hitchhiker's Guide
xyok
V2EX  ›  Python

django model 扩展

  •  
  •   xyok · 2017-03-09 21:49:52 +08:00 via iPhone · 1131 次点击
    这是一个创建于 2612 天前的主题,其中的信息可能已经有所发展或是发生改变。
    写了个 function ,如何让该方法成为所有 model 的成员函数,而不是每个 model 都写一遍
    2 条回复    2017-03-09 22:56:37 +08:00
    jmc891205
        1
    jmc891205  
       2017-03-09 22:13:28 +08:00 via iPhone
    继承呀
    xujinkai
        2
    xujinkai  
       2017-03-09 22:56:37 +08:00 via Android
    把这个 function 放进一个 class 里 然后所有 model 都继承一下
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   1354 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 27ms · UTC 16:51 · PVG 00:51 · LAX 09:51 · JFK 12:51
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.