Login

Tag "management"

Snippet List

Script factory for monitoring django-sphinx with Nagios

This snippet is used to create a script for monitoring sphinx status with Nagios via [django-sphinx](http://code.google.com/p/django-sphinx/). It returns 0 (OK) or 2 (CRITICAL). Remember to change this strings `ModelToMonitor` and `app_name`. Usage : `./manage your-controls-command --log` > /your/script/name.py

  • sphinx
  • script
  • management
  • nagios
  • monitoring
  • django-sphinx
  • factory
Read More

Monitoring django-sphinx for Nagios

This snippet is used to monitor sphinx status via [django-sphinx](http://code.google.com/p/django-sphinx/). It returns 0 (OK) or 2 (CRITICAL). Remember to change this strings `ModelToMonitor` and `app_name`. Usage : `./manage your-controls-command --log`

  • sphinx
  • management
  • nagios
  • monitoring
  • django-sphinx
Read More

Database Cache Management View

A simple view used to manage the page cache stored in the database (here Postgresql in the django_cache table, you also have to set correctly CACHE_TABLE_OID, by the OID of the cache table (you can get it in PgAdmin)

  • admin
  • cache
  • view
  • postgresql
  • management
Read More

collectmedia command: Copy or link media files from installed apps

This management command discovers media files from all `INSTALLED_APPS` (or the apps you specify) and copies or links them to `MEDIA_ROOT`. Put this code in a file like so: yourapp/management/commands/collectmedia.py ...and don't forget the necessary `__init__.py` files. This command includes an interactive mode (`-i` or `--interactive`) and a dry run mode (`-n` or `--dry-run`) for previewing what will happen. See `manage.py help collectmedia` for more options.

  • media
  • management
  • command
Read More

Command to make fixtures.

"Make fixture" command. Highly useful for making test fixtures. Use it to pick only few items from your data to serialize, restricted by primary keys. By default command also serializes foreign keys and m2m relations. You can turn off related items serialization with `--skip-related` option. How to use: python manage.py makefixture will display what models are installed python manage.py makefixture User[:3] or python manage.py makefixture auth.User[:3] or python manage.py makefixture django.contrib.auth.User[:3] will serialize users with ids 1 and 2, with assigned groups, permissions and content types. python manage.py makefixture YourModel[3] YourModel[6:10] will serialize YourModel with key 3 and keys 6 to 9 inclusively. Of course, you can serialize whole tables, and also different tables at once, and use options of dumpdata: python manage.py makefixture --format=xml --indent=4 YourModel[3] AnotherModel auth.User[:5] auth.Group

  • serialize
  • admin
  • model
  • fixtures
  • tests
  • test
  • management
  • commands
  • fixture
  • command
  • make
Read More

Command Line Script Launcher

I often write short test or development scripts that are intended as one-offs. I typically want to execute these scripts from the command line but am always forgetting the necessary steps to set up the Django environment [as described here][bennett]. This snippet allows you execute arbitrary Python scripts from the command line with the context of a given project: python manage.py execfile /path/to/some/script.py Add the code to a file named `execfile.py` within the `management/commands` directory of one of your apps ([see here][ref] for details). [ref]: http://www.djangoproject.com/documentation/django-admin/#customized-actions "Customized Actions" [bennett]: http://www.b-list.org/weblog/2007/sep/22/standalone-django-scripts/ "Standalone Django Scripts"

  • script
  • management
  • execfile
Read More

backupdb command

`backupdb` command allows to make a database backup automatically. It's supposed to do this just before a `syncdb`, `reset` or `flush` command in a server deployment. A usual upgrade task in production server could be: ./manage.py backupdb ./manage.py reset myapp ./manage.py syncdb Put this code in your project's `management/commands/backupdb.py` file.

  • management
  • command
  • django-admin
Read More

Command to dump data as a python script

This creates a fixture in the form of a python script. Handles: 1. `ForeignKey` and `ManyToManyField`s (using python variables, not IDs) 2. Self-referencing `ForeignKey` (and M2M) fields 3. Sub-classed models 4. `ContentType` fields 5. Recursive references 6. `AutoField`s are excluded 7. Parent models are only included when no other child model links to it There are a few benefits to this: 1. edit script to create 1,000s of generated entries using `for` loops, python modules etc. 2. little drama with model evolution: foreign keys handled naturally without IDs, new and removed columns are ignored The [runscript command by poelzi](http://code.djangoproject.com/ticket/6243), complements this command very nicely! e.g. $ ./manage.py dumpscript appname > scripts/testdata.py $ ./manage.py reset appname $ ./manage.py runscript testdata

  • dump
  • manage.py
  • serialization
  • fixtures
  • migration
  • data
  • schema-evolution
  • management
  • commands
  • command
Read More

Control FCGI processes through management

Add fcgi to settings.INSTALLED_APPS then you can start and stop FCGI through manage.py >python manage.py startfcgi >python manage.py stopfcgi In settings define runfcgi arguments using **FCGI_*** in settings For example: >FCGI_SOCKET='/var/tmp/project.sock' >FCGI_PIDFILE='/var/run/project.pid' One of **FCGI_SOCKET** or **FCGI_HOST**/**FCGI_PORT** will need to be defined, but if you forget they will error out. **FCGI_PIDFILE** is required to be defined to allow the process to be terminated.

  • management
  • fcgi
Read More

freshdb management command

This is useful especially during the model-creation stage, when things are in constant flux. The `freshdb` command will drop the project's database, then create a new one. A common use case: manage.py freshdb manage.py syncdb

  • db
  • database
  • management
Read More

extras.py for management commands

! Note - no longer needed Save this script in the same directory as manage.py and run it through the command line. It picks up project Command class instances. Something that will hopefully be fixed in the Django SVN version soon. Heres an example of a command: #utils/management/commands/sqlallall.py from django.core.management import call_command from django.core.management.base import BaseCommand from django.db import models class Command(BaseCommand): help = "Returns sqlall for all installed apps." def handle(self, *args, **options): """ Returns sqlall for all installed apps. """ for app in models.get_apps(): call_command("sqlall", app.__name__.split(".")[-2])

  • management
  • commands
Read More

29 snippets posted so far.