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 @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 Тренды
- 1. LINGORM HER AND HERS FANCON 341K posts
- 2. #BUNCHITA 1,470 posts
- 3. Frankenstein 82.1K posts
- 4. #KirbyAirRiders 1,895 posts
- 5. Giulia 15.6K posts
- 6. taylor york 8,854 posts
- 7. Tulane 4,466 posts
- 8. #SmackDown 48K posts
- 9. Supreme Court 183K posts
- 10. Aaron Gordon 5,022 posts
- 11. #TheLastDriveIn 4,023 posts
- 12. #River 4,835 posts
- 13. Pluribus 31.3K posts
- 14. Justice Jackson 6,093 posts
- 15. Brown Jackson 5,696 posts
- 16. Connor Bedard 3,211 posts
- 17. Gozyuger 2,264 posts
- 18. Russ 14.4K posts
- 19. Tatis 2,242 posts
- 20. Northwestern 5,134 posts
Something went wrong.
Something went wrong.