推荐学习书目
› 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
pythonee
V2EX  ›  Python

[django]怎么实现字段的联动呢

  •  
  •   pythonee · Apr 12, 2015 · 3606 views
    This topic created in 4185 days ago, the information mentioned may be changed or developed.
    假设存在以下model

    class model():
    type = charField(chioics={"按里程计价","按时间计价"})
    distance = integerField()
    during = decimalField()


    有两种计价方式,type显示为下拉框,现在想根据下拉框不同的值,也即是不同的计价方式,填写不同的属性,就是说,当选择“按里程计价”时,就只看到distance这个字段,during就隐藏,而“按时间计价”被选择市,distance就隐藏,这里有种想实现动态显示field_set的感觉
    4 replies  •  2015-04-13 00:33:21 +08:00
    twor2
        1
    twor2  
       Apr 12, 2015
    新手的一点思考

    在模板 html 里面用
    <% ifequal type '按里程计价' %>
    <div class='distance'></div>
    <% endifequal %>

    <% ifequal type '按时间计价' %>
    <div class='during'></div>
    <% endifequal %>

    但下拉框选,type 怎么赋值?

    估计不是django 的问题,而是js的问题
    tidewind
        2
    tidewind  
       Apr 13, 2015
    两个做法

    1:如果对价格实时性要求较高可以在view里接受页面提交的计价类型,对model里进行查询,页面select时发起ajax请求

    2:在view时将两种计费方式都render到页面上,可以存储到隐藏域或者js变量里,然后在select时分别显示这两个值

    一般情况下建议第二种,性能好一些。
    mornlight
        3
    mornlight  
       Apr 13, 2015 via iPhone
    我怎么感觉你说的效果是js 的任务
    14
        4
    14  
       Apr 13, 2015 via Android
    AngularJS
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Privacy   ·   Solana   ·   894 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 26ms · UTC 22:19 · PVG 06:19 · LAX 15:19 · JFK 18:19
    ♥ Do have faith in what you're doing.