Snippet List
*Incredibly useful for storing just about anything in the database (provided it is Pickle-able, of course) when there isn't a 'proper' field for the job:*
A field which can store any pickleable object in the database. It is database-agnostic, and should work with any database backend you can throw at it.
Pass in any object and it will be automagically converted behind the scenes, and you never have to manually pickle or unpickle anything. Also works fine when querying.
**Please note that this is supposed to be two files, one fields.py and one tests.py (if you don't care about the unit tests, just use fields.py)**
- model
- db
- orm
- database
- pickle
- object
- field
- pickled
Returns 'Morning', 'Afternoon', or 'Evening' in the local timezone (specified in settings). Required pytz. 0000-1200 considered morning, 1200-1800 considered afternoon, 1800-0000 considered evening.
- template
- tag
- templatetag
- time
- display
This is a really useful function I used to create the resized preview images you can see on the [homepage of my site](http://www.obeattie.com/). Basically, it takes the original URL of an image on the internet, creates a resized version of that image by fitting it into the constraints specified (doesn't distort the image), and saves it to the MEDIA_ROOT with the filename you specify.
For example, I use this by passing it the URL of a Flickr Image and letting it resize it to the required size, and then saving it to a local path. It then returns the local path to the image, should you need it. I however just construct a relative URL from the image_name and save that to the database. This way, it's easy to display this image.
Hope it's useful!
- image
- pil
- thumbnail
- resize
obeattie has posted 5 snippets.