Showing posts with label django. Show all posts
Showing posts with label django. Show all posts

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 settings.py by adding following lines:
DEFAULT_FILE_STORAGE = 'storages.backends.apache_libcloud.LibCloudStorage'
DEFAULT_LIBCLOUD_PROVIDER = 'google_storage'
LIBCLOUD_PROVIDERS = {
 'google_storage': {
 'type': 'libcloud.storage.types.Provider.GOOGLE_STORAGE',
 'user': 'yourcloudstorageapikey:)',
 'key': 'yourcloudstorageapisecretkey:)',
 'bucket': 'default-bucket-name',
 }
}
 If you don't create bucket, you can create from shell:
$ ./manage.py shell

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

Saturday, February 21, 2015

[Django] Farkli App Icerisindeki Model'leri Ayni Grupta Gosterebilmek

Django admin'de birbiri ile alakali olan iki farkli app'iniz mevcutsa, bu modelleriniz asagidaki gibi gorunecektir:

[App 1]
- Model 1
- Model 2
[App 2]
- Model 3
Ancak siz bu goruntuyu istemiyor, asagidaki gibi bir goruntu istiyorsunuz:
[App 1]
- Model 1
- Model 2
- Model 3 
Hosgeldiniz! Yapilmasi gereken islem, App 2 altinda bulunan Model 3'un Meta sinifinda o modelin app'inin aslinda App 1 oldugunu soylemek. Onu da boyle yapiyoruz:



Onemli Guncelleme:
Bu degisikligin etkileri sandiginizdan daha buyuk olabilir. Bu islem tam anlami ile Django'nun app mimarisindeki app'inizin adinin degistirilmesi anlamina geliyor. Yani varsayilan olarak app'inizin adi olusturulan klasor ayni iken bunun degistirilmis olmasini sagladik. Buna ek olarak Python'un package yapisi yine klasor adi uzerinden calisacaktir.

Bu guncellemeyi yapmama neden olan case, bu app adini degistirdigim zaman bu Model 3'un Model 2'de Foreign key olarak tanimlandigi yerde hata almaya basladim. Bunun sebebi olaraki su tanimlamaydi:


Artik app adimiz 'app_1' olduguna gore buradakini de gistirmek zorundayiz. Bu durumda modelin refresh edilecegini de uzuntuyle belirtmem gerekiyor. :(