DjangoCon 2022 Porto! Part 1

The official Django conference at Europe - run by the community for the community. September 21st-25th @ Porto, Portugal
Wrote David December 28, 2022

Previous years were complicated due to the COVID-19 pandemic, so many conferences were held just online during those hard times. Fortunately, me and my friend Marek had the opportunity to attend DjangoCon 2022. DjangoCon was held in Portugal, so that was another motivation, for both of us, to visit this beautiful country since we were studying there. With this blog, we would like to briefly point out the lectures/information that interested us the most.

Day 1.

The first day was very interesting, we met many like-minded people who were using the same technology for development. So, we had a lot of common topics with them. Early in the morning we registered for lectures, that were prepared for us, started almost immediately without any downtime.

Hidden gems of Django Admin. Part 1. (Maxim Danilov)

We have to say that Django admin is a really powerfull tool. Maxim Danilov was talking about improvements that can be used to work with django admin, to make work with that tool easier for us.

ModelAdmin auto registry

It is possible to override almost all parts of django admin. Model Admin auto registry is interesting in that way that you do not need to register every admin part manually so, it is also a time saver.

from django.contrib.admin import apps as adminApps, sites

class AdminConfig(adminApps.AdminConfig):
    default_site = 'admins.admin.WpAdminSite'

    def ready(self, *args, **kwargs):
   	 super().ready(*args, **kwargs)
   	 site = sites.site  # changed with multiple admin sites
   	 site._register = {}  # remove old registrations

   	 for config in apps.get_app_configs():
   		 admins = getattr(config.module, 'admin', None)

   		 for model in config.get_models():  # excluded auto_created and swapped
   			 model_admin = getattr(admins, f'{model.__name__}Admin', None)

   			 if model_admin and not site.is_registered(model):
   				 site.register(model, model_admin)

With custom autoregistry admin config you do not have to register every model. Instead of this:

from django.contrib.admin import ModelAdmin
from core.models import Shop

@admin.register(Shop)
class ShipAdmin(ModelAdmin):
	list_display = ('title',)

Admin file will look like this:

from django.contrib.admin import ModelAdmin

class ShipAdmin(ModelAdmin):
	list_display = ('title',)
Django admin API

To avoid manually creating API's for simple sites it is possible to return django admin response as json.

Simple solution:

class JsonizedAdminSite(AdminSite):

	def index(self, request, *args, **kwargs):
		response = super().index(request, *args, **kwargs)
		return JsonResponse(response.context_data,
		                    status=response.status_code,
		                    encoder=MyJsonEncoder)

Admin index site context has returned as json. Maxim also shared solution to override the whole model admin to be used as API.

Maxim talked about more interesting and useful tips like:

  • how to sort admin apps on dashboard
  • how to work with auto register multiple site admins
  • how to speed up django admin and prevent calling the same methods multiple times per one request Video from presentation: https://youtu.be/HJfPkbzcCJQ

Kagi useful tool for Multi-Factor Authentication

Really powerful package for Multi-Factor Authentication was mentioned by Justin Mayer during his interesting presentation. Add Multi-Factor Authentication (MFA) to Django in Mere Minutes. When he presented fast solution for install and configure kagi for new project. Video: https://youtu.be/aannTf_z1XU

Django Ninja

Django Ninja looks to be extremely interesting Django rest framework, which suprised me with speed, integration and nice documentation. I haven't tested it personally yet. But initial implementation, test results and comparison with other rest frameworks that were presented by Vitaliy Kucheryaviy during Introducing Django Ninja(presentation video: https://youtu.be/zpR1QCLBpIA) was amazing and you can see base comparison from documentation page(https://django-ninja.rest-framework.com/) below.

https://django-ninja.rest-framework.com/img/benchmark.png

As you can see the comparison it looks that it is much faster than Django Rest Framework or Flask+marshmallow, so I would really like to test it and see how powerful it is.

Day 2.

Better managing i18n and PO files(Felix Mino)

Django internationalization process can be sometimes really hard to maintain because PO files that are used for translation in Django can get huge in size. So, it can be difficult, or it can take long time to translate bigger pages. Felix Mino told us about how to standardize the process for translating pages and how to avoid big unreadable files. Apart from that he offered us much more information in his presentation.

Company name

With any assignment, any client's request we look further and aim to do more than might be enough for others.

Postal address

Adaptiware, spol. s r.o.
Južná trieda 8
04001 Košice
Slovak republic

+421 905 724 771

© 2013 - 2024 - Adaptiware, spol. s r.o.