Django: passing JSON from view to template

If a frontend library needs a to parse JSON, you can use the json library to convert a python dict to a JSON valid string. Use the escapejs filter import json def foo(request): json_string = json.dumps(<time_series>) render(request, “foo.html”, {‘time_series_json_string’: json_string}) <script> var jsonObject = JSON.parse(‘{{ time_series_json_string | escapejs }}’); </script>

Creating Partial Indexes with Django 1.7

Django 2.2 and later As of version 2.2 Django supports declarative partial unique indexes on databases that support them (PostgreSQL and SQLite). So you could do something like: from django.db.models import Model, Q, UniqueConstraint class Post(Model): … class Meta: constraints = [ UniqueConstraint( fields=[“title”, “blog”, “category”], name=”idx1″, condition=Q(category__isnull=False)), UniqueConstraint( fields=[“title”, “blog”], name=”idx2″, condition=Q(category__isnull=True)), ] Django … Read more

Django: AppRegistryNotReady()

If you are using your django project applications in standalone scripts, in other words, without using manage.py – you need to manually call django.setup() first – it would configure the logging and, what is important – populate apps registry. Quote from Initialization process docs: setup() This function is called automatically: When running an HTTP server … Read more