Adaptiware Logo
DjangoPython

DjangoCon 2022 Porto! Part 1

DavidDavid
4 min read
DjangoCon 2022 Porto! Part 1

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.

Speaker: Maxim Danilov

We have to say that Django admin is a really powerful 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.

Python
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:

Python
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:

Python
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:

Python
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 - Multi-Factor Authentication

Speaker: Justin Mayer

Really powerful package for Multi-Factor Authentication was mentioned by Justin Mayer during his interesting presentation. Kagi is a useful tool for adding Multi-Factor Authentication (MFA) to Django in mere minutes. He presented fast solution for install and configure kagi for new project.

Video: https://youtu.be/aannTf_z1XU

Django Ninja

Speaker: Vitaliy Kucheryaviy

Django Ninja looks to be extremely interesting Django rest framework, which surprised 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 during the presentation was amazing.

Django Ninja BenchmarkDjango Ninja Benchmark

As you can see from 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.

Video: https://youtu.be/zpR1QCLBpIA

Day 2

Better managing i18n and PO files

Speaker: 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.

Conclusion

The first two days of DjangoCon 2022 were packed with valuable insights and practical tips. From Django admin optimizations to modern REST framework alternatives, the conference provided excellent learning opportunities. Stay tuned for Part 2 where we'll cover more exciting presentations from the remaining days!

#django#python#conference#djangocon#porto
David

David

Full-Stack Developer at Adaptiware