Posts in "Django" category

Featured Image

Django And MySQL: Model Saving Order Is Important

 Nov. 19, 2021    0 comments 

Often in one Django view you need to save multiple models that have "parent-child" relationship. For example, your view may receive data from a traditional HTML form that includes an inline formset or a JSON with a nested array of child objects from a JavaScript frontend app. In this case you need to save a parent model and create/update/delete some child models. Of course, to make the whole operation atomic all model saves should be wrapped in a database transaction to ensure the consistency of saved data. Let's assume we are using MySQL or MariaDB as a database backend for our Django project. And the question arises: "in which order we should save our models?". "What should we save first: parent or children?" (...)

Read post

 DjangoMariaDBMySQLPython

Featured Image

Formsets In Django Class-based Views

 Dec. 14, 2020    0 comments 

Django offers several out-of-the-box class-based views, including CreateView and UpdateView, that allow you to quckly implement basic CRUD functionality in your web-application without much of boilerplate code. Under the hood CreateView and UpdateView classes create, validate and save a Django ModelForm instance tied to your model class. But sometimes you need to create/edit related model instances along with the main model on the same page. (...)

Read post

 DjangoPython

Featured Image

Bootstrap4-based Pagination Buttons for Django ListView

 May 11, 2018    0 comments 

Often, when displaying multi-page lists in html pages rendered from Django templates, we need to include a pagination control, usually a set of navigation buttons, that is both functional and good looking. In this post I'll describe the solution used in this blog to paginate the list of search results. (...)

Read post

 DjangoHTMLPython

Featured Image

My Blog's New Look

 May 6, 2018    0 comments 

As you can see I have completely re-worked this blog's design. The new skin is based on Bootstrap 4 and hopefully is more pleasant looking than the old one.

Read post

 DjangoHTML

Featured Image

Blog Environment Upgrade

 April 21, 2017    0 comments 

Previously, this blog run on Django 1.8 and Python 3.4, but after a new Django LTS release — 1.11 — I decided that it's time to upgrade this blog to the new Django version and to bump Python version as well. The upgrade process was simple: I created a new virtual environment, installed all the dependencies and pointed Pythonanywhere to this new environment. The blog itself required only one minor change of the sitemap view because URL patterns no longer accept view names as strings, e.g. 'django.contrib.sitemaps.views.sitemap', but require proper callable view objects (previously, both variants were supported).

Now this blog runs on Django 1.11 and Python 3.5 (Pythonanywhere does not provide Python 3.6 yet).

Read post

 DjangoPython