Login

Snippets by stringify

Snippet List

CSV serializer

CSV serialization for models. Can be used via the dumpdata/loaddata management commands or programmatically using the django.core.serializers module. Supports multiple header lines and natural keys. Add the following to settings.py: SERIALIZATION_MODULES = { 'csv' : 'path.to.csv_serializer', } Examples of usage: $ python manage.py dumpdata --format csv auth.user > users.csv from django.core import serializers csvdata = serializers.serialize('csv', Foo.objects.all()) To run the regression tests distributed with the Django tarball: $ cd /path/to/Django-1.2.x/tests $ PYTHONPATH=/path/to/myproject ./runtests.py --settings=myproject.settings serializers_regress

  • csv
  • serializer
Read More

RedirectedURLField

This field is similar to the standard URLField, except it checks the given URL for a HTTP 301 response (permanent redirect) and updates its value accordingly. For example: >>> url = RedirectedURLField() >>> url.clean('http://www.twitter.com/') >>> 'http://twitter.com/' In models: class TestModel(models.Model): url1 = RedirectedURLField('Redirected URL') url2 = models.URLField('Standard URL')

  • url
  • redirect
  • field
Read More

stringify has posted 2 snippets.