'django' Tag

  • django registration form custom field

    Июнь 1, 2010

    In most cases when a user registers in your django application you need to know more than just user name, password and e-mail. To add custom fields to the registration form you should pass form_class parameter to the register view function — it’s easy, but saving additional data could be rather complex. There are solutions […]

  • check login decorator for json responses

    Март 21, 2010

    Django has a login_required decorator that redirects to the login page if user is not authenticated, here I’ll show how to write a custom decorator for json responses. If the uses is authenticated then decorated function returns the desired data otherwise some error in json format. NB — this decorator is for view functions with […]

  • dynamic forms in dajngo

    Март 18, 2010

    Django has a very convenient forms framework and I want to show how to implement a form with dynamic set of fields. First — declare a form class: from django import forms class SomeAddressForm(forms.Form): pass Then the tricky part — declare a function that returns type of dynamic form: def getAddressForm(addMoreField): fields = {«city» : […]

  • Have ascii coding error in django admin?

    Март 10, 2010

    If you have some unicode data in tables e.g. some Russian names and want them to be displayed  by default you need to do some trick: class SomeTable(models.Model): name = models.CharField(max_length=def_max_length) def __unicode__(self): return «%s» % self.name See that — instead of returning self.name directly I returned «%s» % self.name and admin panel is shining!

  • Django is slow?

    Март 2, 2010

    Check that Debug=False and that Google Analytics is off! In my case analytics slows speed dramatically.

  • django: Comments from authenticated users

    Январь 25, 2010

    Djano has a beautiful application — django.contrib.comments. And what is even more beautiful that it is customizable! So I’ll describe how to customize it so that only authenticated users are able to leave comments and comments must contain some rating — I will call such comments reviews. First, create an overridden comments application in a […]

  • get_comment_list reversed

    Январь 23, 2010

    Django has comments application and it works fine for me, except that I need comments in the reversed order. I could have used reversed order in the {% for %} tag, but this doesn’t work with pagination as pagination wants already prepared list. So I wrote a separate filter: from django.template import Library register = […]

  • urllib and cookies

    Сентябрь 10, 2009

    urllib не имеет поддержку куки и протестировать джанго-приложение, использующее сессии затруднительно (идентификатор сессии хранится в куки). Но urllib2 поддерживает куки: import urllib2, cookielib jar = cookielib.CookieJar() handler = urllib2.HTTPCookieProcessor(jar) opener = urllib2.build_opener(handler) urllib2.install_opener(opener) data = urllib2.urlopen(someurl).read() Источник: http://coding.derkeiler.com/Archive/Python/comp.lang.python/2006-04/msg04229.html

  • {% with %}

    Июль 8, 2009

    Очень, на мой взгляд, полезный тэг в шаблонах джанги, который позволяет очень элегантно удалять дупликацию! Например, у вас есть 30 мест, куда вы хотите вставить состояние чего-либо, например сбора данных и писать туда «В процессе» или «Готово», так же у вас есть 30 объектов которые приходят в шаблон, у которых есть метод state() возвращающий логическую […]

  • Odd-even table rows with Django

    Июль 2, 2009

    Вот так можно просто раскрасить табличку при помощи шаблонов джанго: <table> {% for item in data %} <tr {% if not forloop.counter|divisibleby:»2″ %} class=»odd» {% endif %} > <td> {{item.name}} </td> </tr> {% endfor %} </table>

 
Powered by Wordpress and MySQL. Theme by Shlomi Noach, openark.org