Django

Backing up your Django database

python

First dump all the data in a file: » python manage.py dumpdata > data.json or » python manage.py dumpdata > data.json –natural Now load the data to your new database: » python manage.py loaddata data.json

Django / Python Query with variable number of arguments

python

Put all conditions in a kwargs dictionary: kwargs = {} kwargs[‘price__gt’] = 20 kwargs[‘category’] = ‘televisions’ kwargs[‘language’] = ‘NL/nl’ records = Product.objects.all().filter(**kwargs).select_related().order_by(‘order’) Does the following: Select all instances of de Product-model with a price higher then 20, in the category ‘televisions’ and language ‘NL/nl’.