Skip to content
Muslu Yüksektepe

Django ile teknik servis formu (Python 3)

The Python 3 version of the Django 1.9 technical service form guide.

This repository contains the Python 3 version of the Turkish guide to building a technical service form site with Django 1.9. I had prepared the first version, written with Python 2, in January 2016 for djangoturkiye.com. Shortly afterwards, I ported the code to Python 3 for people who wanted to start Django directly with Python 3. I prepared this version together with Korhan Yüzbaş, and we shared it under the MIT licence.

Purpose

At the start of 2016 Python 2 was still widely used, but it was clear that beginners should start with Python 3. Someone reading the guide and trying to run the code with Python 3 could hit errors at the very first step because of print statements, Unicode strings and differences in model definitions. I opened this repository to offer a version of the same sample application that runs directly on Python 3. The topics and the structure of the application stayed the same as in the Python 2 version; what changed was the way the code is written.

Sample application

As in the Python 2 version, the application consists of a single Django app called servisformu. Customers, technicians, accessories and work statuses are kept in separate tables. Each service form is linked to a customer and to the technician who received it, and up to five products can be added under the form. From the admin panel you can call a customer, bulk-update records and open a printable service slip for every form. On the home page, a customer can check the status of their device with their form number through AJAX. Service forms can also be exported as XML.

Changes made for Python 3

I did the first conversion. Korhan Yüzbaş then reviewed the code and brought it closer to the style recommended by Python 3 and Django.

  • print statements were turned into Python 3's print() function.
  • The __unicode__ definitions in the models were changed to __str__.
  • The u prefixes in front of strings and the encoding lines at the top of files were removed, since they are unnecessary in Python 3.
  • Django's get_random_string function replaced Python's random and string modules for the customer code and form number. These fields were also marked as unique.
  • The default value of BooleanField fields was written as True instead of 1.
  • The default_app_config line was removed, because the app is registered in INSTALLED_APPS as servisformu.apps.ServisformuConfig.
  • PostgreSQL was tried for a while, but the project went back to SQLite so that readers of the guide could start without any extra installation.

Who it is for

Anyone who wants to start Django with Python 3 can run the code in this repository directly. The detailed explanations of the topics are in the PDF guide in the Python 2 repository. Reading the two repositories side by side also shows concretely what changes in a Django project when moving from Python 2 to Python 3.

Category
Teaching & community
Year
2016

Technologies

  • Python
  • Django
  • Education

Links

  • GitHub https://github.com/muslu/django-teknikservis-py3

Back to all projects