Django’s ModelForm unique_together validation

I solved this same problem by overriding the validate_unique() method of the ModelForm: def validate_unique(self): exclude = self._get_validation_exclusions() exclude.remove(‘problem’) # allow checking against the missing attribute try: self.instance.validate_unique(exclude=exclude) except ValidationError, e: self._update_errors(e.message_dict) Now I just always make sure that the attribute not provided on the form is still available, e.g. instance=Solution(problem=some_problem) on the initializer.

Collectstatic error while deploying Django app to Heroku

I just updated to Django 1.10 today and had the exact same problem. Your static settings are identical to mine as well. This worked for me, run the following commands: disable the collectstatic during a deploy heroku config:set DISABLE_COLLECTSTATIC=1 deploy git push heroku master run migrations (django 1.10 added at least one) heroku run python … Read more

How do I display the value of a Django form field in a template?

This was a feature request that got fixed in Django 1.3. Here’s the bug: https://code.djangoproject.com/ticket/10427 Basically, if you’re running something after 1.3, in Django templates you can do: {{ form.field.value|default_if_none:”” }} Or in Jinja2: {{ form.field.value()|default(“”) }} Note that field.value() is a method, but in Django templates ()‘s are omitted, while in Jinja2 method calls … Read more

Simple Log to File example for django 1.3+

I truly love this so much here is your working example! Seriously this is awesome! Start by putting this in your settings.py LOGGING = { ‘version’: 1, ‘disable_existing_loggers’: True, ‘formatters’: { ‘standard’: { ‘format’ : “[%(asctime)s] %(levelname)s [%(name)s:%(lineno)s] %(message)s”, ‘datefmt’ : “%d/%b/%Y %H:%M:%S” }, }, ‘handlers’: { ‘null’: { ‘level’:’DEBUG’, ‘class’:’django.utils.log.NullHandler’, }, ‘logfile’: { ‘level’:’DEBUG’, … Read more

How can I use redis with Django?

This Python module for Redis has a clear usage example in the readme: http://github.com/andymccurdy/redis-py Redis is designed to be a RAM cache. It supports basic GET and SET of keys plus the storing of collections such as dictionaries. You can cache RDBMS queries by storing their output in Redis. The goal would be to speed … Read more

Django – Static file not found

I confused STATIC_ROOT and STATICFILES_DIRS Actually I was not really understanding the utility of STATIC_ROOT. I thought that it was the directory on which I have to put my common files. This directory is used for the production, this is the directory on which static files will be put (collected) by collectstatic. STATICFILES_DIRS is the … Read more

How do you configure Django for simple development and deployment?

Update: django-configurations has been released which is probably a better option for most people than doing it manually. If you would prefer to do things manually, my earlier answer still applies: I have multiple settings files. settings_local.py – host-specific configuration, such as database name, file paths, etc. settings_development.py – configuration used for development, e.g. DEBUG … Read more