Login

Snippets by alia_khouri

Snippet List

easy admin registration

This essentially wraps [snippet 917](http://www.djangosnippets.org/snippets/917/) (with full credit to author ncw) in a convenience function so that you can type: admin_register(admin, namespace=globals()) or more concisely: admin_register(admin, globals()) at the end of your admin.py file without having to register each model and admin class individually.

  • admin
  • register
Read More

djangopath: conveniently set sys.path and DJANGO_SETTINGS_MODULE

In the past, whenever I had a script that I wanted to properly configure the settings for, I would use something like the following idiom at the top of the script: import sys, os; dirname = os.path.dirname # sys.path.insert(0, dirname(dirname(__file__))) sys.path.insert(0, dirname(__file__)) os.environ['DJANGO_SETTINGS_MODULE'] = 'myapp.settings' Notice that this is a relative setting to `__file__` variable in the script. The djangopath function is an attempt to do away with the above such that I can now write the following: from lib import djangopath; djangopath(up=2, settings='myapp.settings') This seems to work for me, but it assumes that you are packaging your script inside your projects/apps. If they are elsewhere then you may need to resort to another method (e.g. absolute paths, etc.) AK

  • settings
  • path
Read More

alia_khouri has posted 2 snippets.