Login

Tag "django"

Snippet List

range tag

Create a list containing an arithmetic progression that can be iterated through in templates. Emulate the [range](http://docs.python.org/library/functions.html#range) syntax. You can use either numbers or variables. Syntax: {% num_range [start] stop [step] as some_range %} {% for i in some_range %} ... do something {% endfor %} **About the author**: Take a look at [my website](http://www.marcofucci.com)

  • template
  • tag
  • django
Read More

VAT field

VAT field with a field to select the country and a free field for the code

  • django
  • fields
  • forms
  • form
  • field
  • formfield
  • vat
  • tva
Read More

Django Breadcrumbs Snippet

A simple tag to render breadcrumbs. Usage: {% load breadcrumbs %} {% breadcrumbs "['Home','Home','home']" "['Articles','Articles','articles']" "['object','object','object.get_absolute_url']" %} Loads up the template in "modules/breadcrumbs.html" and renders it with a list of items. You can provide the tag either with plain text stuff and named urls as the third argument ( any more arguments per bracket-block is parsed as args / kwargs for the reverse() call ) or the object directly, and the script tries after failing the reverse() to resolve the provided arguments. Have pun.

  • django
  • templatetag
  • breadcrumbs
Read More

TwitterBackend

TwitterBackend is the twitter authentication backend. This backend makes use of OAuth based "Sign-in with Twitter" Configure your settings.py as per [Django - Specifying Authentication Backends](http://docs.djangoproject.com/en/dev/topics/auth/#specifying-authentication-backends)

  • django
  • authentication
  • python
  • backend
  • twitter
  • oauth
Read More

Simple Admin-button linking to Databrowse

If you want all the objects in your models' admin interface to have a direct link to their databrowse page (just like the *history* link).. follow these steps: 1) copy the *change_form.html* admin template in mytemplates/admin/ 2) edit *change_form.html* by adding this code right next to (before or after) the following line (=the history button markup): `<li><a href="history/" class="historylink">History</a></li>` 3) Make sure that all of you models are registered with [databrowse](http://docs.djangoproject.com/en/dev/ref/contrib/databrowse/) That's it. Obviously if you don't want ALL the models to have this link, you should use a different recipe, for example this one: [http://www.djangosnippets.org/snippets/1016/](http://docs.djangoproject.com/en/dev/ref/contrib/databrowse/)

  • django
  • admin
  • databrowse
  • button
Read More

Django Drag and Drop Using YUI

I was trying to implement the django inline drag & drop, I cudn't understand. Then I have try with YUI library Copy the above code in the respective .py & download the YUI library and add the JS in your media folder. This will do..., Try this our , it's easy to use..,

  • django
  • yui
  • drag
  • drop
  • and
Read More

Page numbers with ... like in Digg

Digg-like page numbering using inclusion tag. Usage in template: {% load pagination %} {% pagination yourpage %} Inclusion template `pagination.html`: {% load i18n %} <div class="pagination"> <span class="step-links"> {% if page.has_previous %} <a href="?page={{ page.previous_page_number }}" class="previous">{% trans "previous" %}</a> {% endif %} {% for pnum in begin %} {% ifequal page.number pnum %} <span class="current">{{ pnum }}</span> {% else %} <a href="?page={{ pnum }}">{{ pnum }}</a> {% endifequal %} {% endfor %} {% if middle %} <span class="continue">...</span> {% for pnum in middle %} {% ifequal page.number pnum %} <span class="current">{{ pnum }}</span> {% else %} <a href="?page={{ pnum }}">{{ pnum }}</a> {% endifequal %} {% endfor %} {% endif %} {% if end %} <span class="continue">...</span> {% for pnum in end %} {% ifequal page.number pnum %} <span class="current">{{ pnum }}</span> {% else %} <a href="?page={{ pnum }}">{{ pnum }}</a> {% endifequal %} {% endfor %} {% endif %} {% if page.has_next %} <a href="?page={{ page.next_page_number }}" class="next">{% trans "next" %}</a> {% endif %} </span> </div> Produces: previous 1 2 ... 4 5 6 7 **8** 9 10 11 12 ... 17 18 next Or: **1** 2 3 4 5 6 7 8 ... 17 18 next Or: previous 1 2 ... 10 11 12 13 14 15 16 **17** 18 next

  • tag
  • django
  • templatetag
  • pagination
  • digg
  • pages
Read More

HTML/JS template filter to show localized dates/times

While working on my website projects today I had the idea to use HTML/JS instead of a IP database to localize the dates and times shown on the websites. Here are the snippets to use the JS snippets as filters for Django running on Google App Engine. You can use those filters on datetime objects.

  • template
  • filter
  • django
  • datetime
  • date
  • time
  • appengine
  • local
Read More

Changing the locale temporary

This piece of code allows the quickly set the locale to a different language. This can be used for instance in cron jobs to send emails to users in their specific language. This is pretty rough code, it be better to create an object, having two functions: set_locale and reset_locale. set_locale would than contain steps 1 to 4 (and return the request object on succes), reset_locale would be step 6 Enjoy!

  • django
  • locale
Read More

Built-in Slugify with filtering.

This is based on snippets 29 and 43, both of which had good ideas, and I thought, "why not combine them?" Given the new_topic string above, the resulting slug will be: "test-long-string-which-has-many-words-here" John Crawford Note - requires python 2.5, for list comprehensions. Otherwise you could just use a for loop to build the clean_list.

  • django
  • slugify
Read More

ChoiceField with widget in choice

This code creates a widget that we used to generate a list of radiobuttons as follows: * Radio button 1 --Widget__1 * Radio button 2 --Widget__2 * Radio button 3 --Widget__3 How to use it is: `ImagenForm class (forms.ModelForm): widget1 = forms.BooleanField () widget2 = forms.TextInput widget3 = forms.ModelChoiceField (queryset = Modelo.objects.all ()) widget4 = forms.FileInput optConListas = ChoiceWithOtherField (choices = [(2, 'widget1' widget1), (3, 'widget2' widget3.widget), (4, "widget2" widget2), (5, 'widget4' widget4)])`

  • django
  • choice
  • choicefield
  • widget
  • alfonso
Read More

Dynamic growing model

This model is designed for my webshop. The Client-object is very 'stretch-able' by defining more fields to the client. These extra fields ares stored in the ClientConfig-object. Be sure to create a new Client-instance first and SAVE it! Without a client.id the ClientConfig won't work.

  • django
  • dynamic
  • model
  • example
  • client
Read More

213 snippets posted so far.