Thursday, June 25, 2015

[Django] Changing field widget when when using inlines

For example, if you create a SiteOption model to extend Django's core sites framework you may want to add multiple inlines from one model (SiteOption) for grouping options, like:

General Options
Theme Options
Security Options
SEO Options

"Show me the code!"

Wednesday, June 17, 2015

[Django] Using cloud storage services as default storage backend

To use cloud storage services as default storage backend in Django – or actullay in Python, Apache's Libcloud wrapper can be a nice solution. Because it supports more than 30 providers, and has a huge community.

django-storages-redux app provides storage backends to use in Django. Good news, also supports Apache Libcloud. So you can use more than 30 cloud providers with Django. To install the app execute this:
$ pip install django-storages-redux
Also you must install Apache Libcloud:
$ pip install apache-libcloud
And enable from by adding following lines:
DEFAULT_FILE_STORAGE = 'storages.backends.apache_libcloud.LibCloudStorage'
 'google_storage': {
 'type': '',
 'user': 'yourcloudstorageapikey:)',
 'key': 'yourcloudstorageapisecretkey:)',
 'bucket': 'default-bucket-name',
 If you don't create bucket, you can create from shell:
$ ./ shell

$ from storages.backends.apache_libcloud import LibCloudStorage
$ LibCloudStorage('google_storage').driver.create_container('default-bucket-name')

Wednesday, June 10, 2015

Detecting if an image is really an image

About Technique

HTTP protocol has really cool methods such as HEAD. HEAD method allows you to get only head data instead of head and body. Head data contains mimetype of the body, so we can rely on it to detect if it's really an image. Let's get it with JavaScript...

The Code

Sync Example

Async Example

As you can see, you can even detect huge images very quickly. ;)

Originally posted at