QSerializer with default to JSON input and output
A module to serializers/deserializes Django Q (query) object
- serialize
- django
- json
- q
- query
A module to serializers/deserializes Django Q (query) object
Ever tried to unit test custom fields or abstract models? If so, you probably used a solution like [this one](http://djangosnippets.org/snippets/2843/). It surely works, but it has some issues: 1. Runs 'syncdb' several times. 2. It's not automatic. You must add the mixin or copy the code to each of the TestCases. This test runner adds to INSTALLED_APPS the 'app.tests' package for **each of the specified** apps, **before the 'syncdb' happens**. This has the [discovery runner](https://pypi.python.org/pypi/django-discover-runner) as a dependency (for 1.5 only, it will be the default in 1.6). However, it comes as a mixin so it should be easily pluggable to other test runners. If you intend to use the mixin with other runners, note that it imports 'app.tests.models' so it won't work with tests modules (tests.py). Your runner must "use" test packages (like discovery runner). # USAGE # in your settings.py: TESTAPPS_INSTALL = ( 'app1', 'app2', # ... ) TEST_RUNNER = 'testapp_runner.DiscoverTestAppRunner' # example import path # extra apps in command line. # run test for apps 'app1' to 'app4', adding 'app3' and 'app4' to the TESTAPPS_INSTALL setting. manage.py test app1 app2 app3 app4 --with-test-app=app3 --with-test-app=app4
Create a random integer with given length. - For a length of 3 it will be between 100 and 999. - For a length of 4 it will be between 1000 and 9999. Use it in a template like: {% random_number as my_id %} The id is {{ my_id }}
You can see full examples on the page [GitHub](https://github.com/abbasovalex/django-SplitJSONWidget-form)
middleware to capture exceptions doesnotexists,objectdoesnotexists
This is another fork of http://djangosnippets.org/snippets/2729/ that fixes the issue. Unlike those other versions i give you instructions so it works for you, this is modified a little. Instructions: If you want to import the passwords from drupal you need to prepend to each of them the word drupal so it looks like this: drupal$S$DQjyXl0F7gupCqleCuraCkQJTzC3qAourXB7LvpOHKx0YAfihiPC Then add this snippet to someapp/hashers/DrupalPasswordHasher.py And then in your settings add this: PASSWORD_HASHERS = ( 'django.contrib.auth.hashers.PBKDF2PasswordHasher', 'someapp.hashers.DrupalPasswordHasher', 'django.contrib.auth.hashers.PBKDF2SHA1PasswordHasher', 'django.contrib.auth.hashers.BCryptPasswordHasher', 'django.contrib.auth.hashers.SHA1PasswordHasher', 'django.contrib.auth.hashers.MD5PasswordHasher', 'django.contrib.auth.hashers.CryptPasswordHasher', ) So, what did i modify First i added the attribute algorithm to the class, django uses this word to identify wich hasher to use, so the passwords beggining with drupal should be verified with the hasher.algorithm == 'drupal' Ok so know django knows to use our class, but now our passwords won't validate because we changed them by adding the word drupal, so what do we do? we modify the verify method to remove the word drupal before verification :P Hope it helps
Adds a CSV export action to any Django model admin that inherits it.
all_models = [ each for each in GetAllModels() ] This produces a list of tuples in format ( app_label's name, model's name) of all the ContentType existing in system.
Usage: {% load helper_tags %} {% get_available_languages as languages %} {% for lang_code, lang_name in languages %} <link rel="alternate" hreflang="{{ lang_code }}" href="{% change_lang lang_code %}"> {% endfor %}
Adds drag-and-drop ordering of rows in the admin list view for Grappelli. This is a updated version of Snippet [#2306](http://djangosnippets.org/snippets/2306/) that works with the current version of Grappelli. The model needs to have a field holding the position and that field has to be made list_editable in the ModelAdmin. The changes of the ordering are applied after clicking 'Save'.
Allows you to make an arbitrary function's results cached for a period of time (also known as memoize).
A management command to automatically generate a fully specified admin for the models in a specific app. It automatically generates raw_id_fields, search_fields, list_filter and more. It bases this on date fields, fields named as "name" or slug. Usage: ./manage admin_autogen <model>
Sometimes using regex is a huge pain
Based on [onecreativenerd](http://djangosnippets.org/users/onecreativenerd/) code. Sometimes it's a real pain to use the @login_required decorator all over the views of a complicated site. This middleware requires login on every page by default and supports a list of regular expression to figure out the exceptions. This way you don't have to worry about forgetting to decorate a view. This snippet requires LOGIN_URL to be set in settings.py, and optionally allows you fill out LOGIN_EXEMPT_URLS, a tuple of regular expressions (similar to urls.py) that lists your exceptions. Example: LOGIN_EXEMPT_URLS = ( r'^about\.html$', r'^legal/', # allow the entire /legal/* subsection )
Append span with text, image or other data to any django widget so bootstrap can format it like in [here](http://twitter.github.com/bootstrap/base-css.html#forms) (scroll to "Extending form controls" section) Example usage: ` example_field = CharField( max_length=255, min_length=1, label='Label', required=False, widget=AppendWidget(base_widget=TextInput, data='@') ) `
213 snippets posted so far.