Profile_bird

Hey there! djangotips is using Twitter.

Twitter is a free service that lets you keep in touch with people through the exchange of quick, frequent answers to one simple question: What's happening? Join today to start receiving djangotips's tweets.

Already using Twitter
from your phone? Click here.

djangotips

  1. we just launched the latest member of the tweetips family! now you can follow @csstips for little bits of CSS goodness too.
  2. via @tkaemming: add "from __future__ import division" at the top of a .py file to force "true division" (no rounding)
  3. via @shacker: to delete *.pyc files, in .profile add: alias delpyc = 'find . -name "*.pyc"* -exec rm {} \;' to use "delpyc" in shell.
  4. via @tkaemming: give your model fields overly descriptive names, and always use help text. you'll thank yourself during maintenance. :)
  5. via @disturbyte: I like to use the JSON parser to parse arguments in custom Django template tags. It's available in django.utils.simplejson.
  6. via @truebosko: Filters can reference fields on the model using the new F() object in 1.1: query.filter(qty_sold__lt=F('quantity'))
  7. via @tkaemming: you can create models in a separate "models" module instead of a models.py file by defining an app_label in your model Meta.
  8. via @truebosko: You can use .as_sql() on a QuerySet to see the RAW SQL it uses. Quick way to debug some queries.
  9. via @davidbgk: Painless doctests debug tool http://tinyurl.com/dzxtbt Usage: >>> import interlude; interlude.interact(locals())
  10. via @swbratcher: Great first run django tutorial/how-to for new users. Illustrates building a to-do app from scratch. http://bit.ly/yGIL
  11. note: context processors & middleware have different purposes that can solve the issue in different situations. that's why we shared both :)
  12. via @howiworkdaily: actually a custom context_processor is better for adding something like shopping_cart to every request, not middleware
  13. via @andrewingram: if you want something available to every request (like a shopping cart), custom middleware might be the answer
  14. via @tkaemming: to recursively remove all of your *.pyc files in a bash terminal, run: find . -name "*.pyc" -exec rm '{}' ';'
  15. via @truebosko: quick inspection of a models fields: you can go through model._meta.fields, e.g [x.__dict__ for x in XY._meta.fields]
  16. via @jacobian: http://twurl.nl/7gtmzk is a better idea than bare "print." Much more flexible.
  17. via @AbeEstrada: add print "variable" in your views.py file and you can debug in terminal
  18. via @andrewingram: adopt the preferred file structure of benchmark Django apps as soon as possible, it lets you work very quickly
  19. via @tkaemming: you can set all your forms to action="" to post a page to its own URL as long as your URL ends with a forward slash.
  20. via @truebosko: Fetch the latest entry within an object using Foo.objects.latest('field_name'). A neater way then slicing your query.