Login

Snippets by dsblank

Snippet List

fast table flush without raw SQL

Perhaps you don't want to drop a table, but you also want to do something faster than Model.objects.all().delete() but without resorting to raw SQL. This function, clear_tables, will call the sql_flush operation on a list of tables.

  • delete
  • flush
  • fast
Read More

a simple tag with context

simple_tag is nice, but it would be useful if it had a "as variable" clause at the end. This little bit of code factors out the reusable parts and makes a tag almost as simple as simple_tag. Now you can create tags like the following: {% some_function 1 2 as variable %} {% some_function db person %} To add a new function, just do: register.tag("new_function", make_tag(new_function)) (I think you have to take the quotes off a string.)

  • context
  • simple_tag
  • as
Read More

dsblank has posted 2 snippets.