djangotips's profile picture. little bits of django goodness in 140 characters or less. and it's all powered by you, the django community. :) dm your tips to @djangotips!

djangotips

@djangotips

little bits of django goodness in 140 characters or less. and it's all powered by you, the django community. :) dm your tips to @djangotips!

we just launched the latest member of the tweetips family! now you can follow @csstips for little bits of CSS goodness too.


via @tkaemming: add "from __future__ import division" at the top of a .py file to force "true division" (no rounding)


via @shacker: to delete *.pyc files, in .profile add: alias delpyc = 'find . -name "*.pyc"* -exec rm {} \;' to use "delpyc" in shell.


via @tkaemming: give your model fields overly descriptive names, and always use help text. you'll thank yourself during maintenance. :)


via @disturbyte: I like to use the JSON parser to parse arguments in custom Django template tags. It's available in django.utils.simplejson.


via @truebosko: Filters can reference fields on the model using the new F() object in 1.1: query.filter(qty_sold__lt=F('quantity'))


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.


via @truebosko: You can use .as_sql() on a QuerySet to see the RAW SQL it uses. Quick way to debug some queries.


via @davidbgk: Painless doctests debug tool http://tinyurl.com/dzxtbt Usage: >>> import interlude; interlude.interact(locals())


via @swbratcher: Great first run django tutorial/how-to for new users. Illustrates building a to-do app from scratch. http://bit.ly/yGIL


note: context processors & middleware have different purposes that can solve the issue in different situations. that's why we shared both :)


via @howiworkdaily: actually a custom context_processor is better for adding something like shopping_cart to every request, not middleware


via @andrewingram: if you want something available to every request (like a shopping cart), custom middleware might be the answer


via @tkaemming: to recursively remove all of your *.pyc files in a bash terminal, run: find . -name "*.pyc" -exec rm '{}' ';'


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]


via @jacobian: http://twurl.nl/7gtmzk is a better idea than bare "print." Much more flexible.


via @AbeEstrada: add print "variable" in your views.py file and you can debug in terminal


via @andrewingram: adopt the preferred file structure of benchmark Django apps as soon as possible, it lets you work very quickly


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.


via @truebosko: Fetch the latest entry within an object using Foo.objects.latest('field_name'). A neater way then slicing your query.


United States Тренды

Loading...

Something went wrong.


Something went wrong.