django : using admin datepicker

后端 未结 3 1548
再見小時候
再見小時候 2020-12-29 10:46

I\'m trying to use the admin datepicker in my own django forms.

Roughly following the discussion here : http://www.mail-archive.com/django-users@googlegroups.com/msg

相关标签:
3条回答
  • 2020-12-29 10:58

    You may find the following works for you:

    <link href="/media/css/base.css" rel="stylesheet" type="text/css" media="screen" />
    <script type="text/javascript" src="/admin/jsi18n/"></script>
    <script type="text/javascript" src="/media/js/core.js"></script>
    {{ form.media }} 
    
    0 讨论(0)
  • 2020-12-29 11:01

    I think I solved the first half by explicitly adding these lines to my template :

    <script type="text/javascript" src="../../../jsi18n/"></script> 
    <script type="text/javascript" src="/admin_media/js/core.js"></script>
    <script type="text/javascript" src="/admin_media/js/admin/RelatedObjectLookups.js"></script>
    

    But it still reports not knowing gettext

    0 讨论(0)
  • 2020-12-29 11:09

    No, it's not a bug.

    It's trying to call the gettext() internationalization function in js. You can do js internationalization much like you do it in python code or templates, it's only a less known feature.

    If you don't use js internationalization in your project you can just put.

    <script>function gettext(txt){ return txt }</script>
    

    in your top template so the js interpreter doesn't choke.

    This is a hacky way to solve it I know.

    Edit:

    Or you can include the exact jsi18n js django admin references to get it working even with other languages. I don't know which one it is.

    This was posted on django-users today:

    http://groups.google.com/group/django-users/browse_thread/thread/2f529966472c479d#

    Maybe it was you, anyway, just in case.

    0 讨论(0)
提交回复
热议问题