Login

All snippets

Snippet List

Database backup with admin command

Detect type of database (MySQL, PostgreSQL or SQLite) and make backup. In this moment ONLY WORK in GNU/Linux, NOT WIN.

  • database
  • admin-actions
  • backup
  • MySQL
  • admin-command
  • SQLite
  • PostgreSQL
Read More
Author: jhg
  • 1
  • 3

Tastypie v0.9.11 LoginRequiredAuthorization

This is an Authorization class for [Tastypie](http://django-tastypie.readthedocs.org/en/latest/authentication_authorization.html) v0.9.11 (v0.9.12 changes how Authorization works). DjangoAuthorization checks specific permissions — `add_model`, `change_model`, `delete_model`, etc. If you don't need that level of permissions checking, this might be useful. It just makes sure the User is logged in. It's equivalent to the `login_required` decorator.

  • login_required
  • tastypie
Read More

Fail Faster: unsafe_test Management Command

The faster you fail the faster you reach success. This management command runs tests within the django environment, but without a test database, hence the word "UNSAFE". It only runs unittests for a single application, which are not subclasses of django.test.TestCase. Django's TestCases are not supported because they attempt to purge the database. Turn this flaw into a feature by segregating testcases into those that either need or don't need the test database. This tool may not be useful in all cases, but in certain cases you can have more rapid testing iterations. I use it for certain utility applications. **Setup:** Place in <app_name>/management/commands/unsafe_test.py **Run:** $./manage.py unsafe_test <app_name>

  • management-command
Read More

Bootstrap button dropdown widget (replaces forms.Select)

You need jQuery and Bootstrap 2 and bootstrap-dropdown.js. Apart from that, this should be a perfect drop-in replacement for the normal select widget. A jQuery event callback maintains a hidden input field from the user's selection. Upon loading the page, the hidden input field is set. The SelectWidgetBootstrap also contains a <noscript> tag containing the normal forms.Select widget. Example usage: class MyForm(forms.Form): group = forms.ModelChoiceField(models.Group.objects.all(), widget=SelectWidgetBootstrap(), empty_label=_(u'(no group selected)'))

  • dropdown
  • select
  • bootstrap
Read More

Convert Q object to function

This is a function to take a Q object and construct a function which returns a boolean. This lets you use the exact same filter syntax that Django's managers use and apply it inside list comprehensions, or to non-persistent objects, or to objects of different types with the same attribute names.

  • q-objects
  • field
  • queryset
Read More

Automatically set up a project

This is a script to automatically set up a django project It takes only one argument for the project name This works for Django 1.4 It will create the following directory structure: /project /server (app name) /media: /html /css /js /img

  • automatic
  • createproject
Read More

Manage.py alterdb command

added commands: altersql - shows sql code with alter queries alterdb - apply alter queries. parameters: --showsql - show queries --app=APPLICATION - alter only selected application [you need clone this repo](https://bitbucket.org/certator/django_snippets)

  • hack
  • table
  • syncdb
  • alter
Read More

3109 snippets posted so far.