Login

Snippets by jkocherhans

Snippet List

Batch querysets

Most of the time when I need to iterate over Whatever.objects.all() in a shell script, my machine promptly reminds me that sometimes even 4GB isn't enough memory to prevent swapping like a mad man, and bringing my laptop to a crawl. I've written 10 bazillion versions of this code. Never again. **Caveats** Note that you'll want to order the queryset, as ordering is not guaranteed by the database and you might end up iterating over some items twice, and some not at all. Also, if your database is being written to in between the time you start and finish your script, you might miss some items or process them twice.

  • queryset
  • batch
Read More

mask_email filter

Mask an email address by removing most of the first portion and replacing it with "..." For example. If you have a variable in your template context named `email_address `, and its value is "[email protected]" {{ email_address|mask_email }} will render as: [email protected] If the part preceding @domain.com is shorter than 5 characters, only the first letter will be used, followed by "...". So if we have "[email protected]" {{ email_address|mask_email }} will render as: [email protected]

  • filters
  • email
Read More

jkocherhans has posted 2 snippets.