Day 3 Lightning Talks
Transcript
By Speaker 1, Speaker 2, Speaker 3, Speaker 4, Speaker 5, Speaker 6, Speaker 7, Speaker 8. From DjangoCon Europe 2024. Published July 11, 2024.
Watch the video Markdown version 6,029 words · auto-generated · en
Summary
Willem van Onsem showed how Django path converters can accept and return model objects, including lazy loading to avoid unnecessary database queries, while warning about ambiguous overlapping patterns and eager lookups. Omar Faruk Baji explained how Django’s `ForeignObject` can model custom joins when an existing database cannot be changed, and stressed testing the resulting relationships. Other speakers gave practical guidance on CVs, Django’s multi-database routing, Grafana OnCall’s Django architecture, and using the multi-tenant Takahē project to run Fediverse identities on your own domains. The closing updates covered Django community fundraising priorities—more fellows, grants, diversity support, and conferences—and the growth of PyCon Portugal, with its next edition planned for Braga.
Transcript
Automatically transcribed, so expect mistakes in names and technical terms. Filler words are removed.
0:00 Model-Based Path Converters
Speaker 1
I I'll let you get ready and I'll start the timer for five minutes. Oh are you ready?
Speaker 2
Yes, I guess.
Speaker 1
Okay, so Yay! Okay, all yours.
Speaker 2
Hello? Oh hello, I am Willem van onsem and I'm going to talk about model-based podconverters, which is actually quite nice because the previous talk also went about podconverters. So most of you probably write a lot of parts like that one if you have for example a view where you want to look at the details of a profile, you I you write a plot with a profile and then the username of that person from which you want to see the profile. And in the view, then of course you receive the username. Thank you. And as a result you make a database query where you look for the user with that username and then you do extra processing. And so my idea was what if we would work with the models directly?
That would mean that we write a pod converter as the one here. So the rechecks is just a sequence of words characters And then you have the two Python methods, which is essential, which basically looks up the user with that username, and if it there is no such username, it raises a value error. That will come up later why that's useful. And then the tourl does the opposite. So it takes a value, which is usually a user. And it then takes it its username as part of the plot. In case it's not a user, we will for now assume that it is a username already, so that no conversion is needed. If we would do that, we can register that pod converter with the name user. username, which makes it clear we are going to fetch a user by its username and we'll pass that
User as the variable user to the profile. Now as a result the view is simplified because it takes as input a user, which is a user object, so it's no longer a string with the username, it's the user object itself. And as a result, if we print, for example, the email of that username and we visit the page, then it will for my username print my user at myhost. org, for example, if that's in the database. And the reverse is also true. If you have a template where you have a user and you do the reverse You only pause the user object and it knows for itself that it has to fetch the username from that user object. So there's no more user.
username. That means that if you later change your mind and would use a email address, for example, instead of the username, you can still use that and you only need to adapt the pod converter for it. Because of the value error, if the pod if the conversion fails, it will look for the next pattern. So that means that you can have overlapping pods So you can have a pod anything that first looks for the user with that username, and if that fails, you look for a group with that name. And you can make a sequence of anything that you want to search for. Now that's y typically not a good idea. Why? Because the username and the group name can overlap and there can be users that have, by accident, the same name
And another problem is you make a lot of queries. First you will look at the user with that name, then to the group with that name, etc. Another problem is we make queries eagerly. Eagerly. That means that if you here for example visit the comment section of an article and you are required to be logged in But you are not, then it will fetch the article first, then check login required, and as a result it will fetch request. user and the articles two queries instead of one if you would do it with the old method But we can resolve that problem. How? Exactly the same way they did it with request. user. They don't fetch the re user every time, they only fetch it when it's needed.
And how do they do that? with lazy objects and we can adapt the pod converter quite easily to a simple lazy object That's an object that promises to fetch the user, but it does not do that unless you need an attribute for it. For example, you need to call string for it, then it will fetch the object. or you need the user at the email address, then it will fetch it as well. So as a result, if we here have a view and only during business hours you can see the user ID, it will do a lot more work during business hours, but not when you are sleeping. So at the first comment line, we have not fetched the user yet. It pretends to be a user and you can have all attributes you want that are on the user object
But only if you really access one it will fetch it from the database. And we also did something similar to bypass foreign key set. So here we will only fetch the article and not the author. That's The last thing I want to say. Okay.
5:09 Dungeons, Dragons, and Django
Speaker 3
Okay, hello everyone. I hope you enjoy the conference. Thank you. So today I will talk about Dungeons, Dragons and Django. So this is me, Omar Faruko Baji. I'm a senior backend warrior with a level five. So it means that like I am I've been working for five years as a back-end developer. And today I will talk to you about a story of mine. So one day when I was wandering around the realms of Django, I encountered a computer and it was begging me to save the Princess Django. And I needed to do that, and I accepted the quest. So then after right after accepting the quest I just start to walking on my way to the castle to save the Princess Chango
And my first warrior was lookups. Actually it was a pretty easy battle for me. I could understand that. But I was at level 1, so I got a bit of a damage But I managed to level up to two. And my next enemy on the way was Subquery monster. And it was hard to understand for me in my second year But I tried my best to beat it, get help from my friends and I could manage to beat it. But of course I got some damage And after continuing my way, I encountered my one of my most scary enemies, staked and prefaced related and this one was a twin-headed monster.
That like was a really tough battle for me but I could manage to beat it with again like asking for my friends reading the handbook that I had which is the Django documentation and then I was in a really bad shape. It's still the ones of that battle hurts time to time. And my last enemy was custom joints. So This was an enemy that I have never seen before. I was looking at the handbook, I couldn't see anything, I searched, I found nothing. And I was wondering that how many of you did to do custom joins with Django before Nice. I see
some people that also encounter this enemy, so I'm not the one. And I was like I Didn't think of anything I needed to go to the source code dungeon, which is a mysterious dungeon, dangerous dungeon, and while wandering around the dungeon I encountered this class, foreign key class, which I was used to. And it was inherited from the foreign object class and I wondered what was that, and I followed the path And in the init method, initialization method of this class, for an object class I to solve two fields, from fields and two fields. And I think that that might be what I was looking for. So actually it was a really
valuable object that I can bring to the battle with me. And now enchanted by the foreign object, I was ready to ready to battle the custom joint. And the first attack came, it was like Nothing. It's a basic class with even with a unique together. So I don't know like if it was trying to help me or what. But then the really real attack begins. So I got this book class book model that has a title that's fine. But for the next three lines I got the bad database design curses from the enemy So the outer idea was an integer field, and there was also outer first name and last name, which are char fields. Normally you would have a foreign key for that, a single foreign
key And I was I think that okay now I can do a refactor to get rid of this and use the foreign key But now enemy was using the managed force magic on me, so I don't have any way to change the database. Now that like that time I remembered the object that I get from dungeon the foreign queue object. So I defined the foreign queue foreign object cla fields on my model And as you can see like from fields is outer ID, two fields is ID, front fields is the fields in the book model and the two fields is the model in the in the other model and I also knew that I couldn't do
it without tests. I wrote all the tests and I defeated the enemy. And thank you all but the princess was in another castle.
10:04 CV and Resume Advice
Speaker 4
Okay, so hello and welcome everyone. I'm Josh. I am a recruiter for Foxy Talent. I won't bore you too much because I probably have already chewed your ear off, but this is going to be about C V advice or resume, as some of you others will ha say. Show of hands. Who calls it a C V? Brilliant. Who calls it resume? You're wrong. I won't go on too much. But I outside of work, I've got twins, married to my wife who've been with fourteen years. Inside of work, I've been doing recruitment for five now. Before that I actually was an estate agent as well. So no booze for that one please. Foxy Talent, as I've said,
quickly what we do Donate to the DSF, we're really proud about that. We are a recruitment company but we also are gold sponsors here and also in DjangoCon US as well and a big one for us is the Django Social which we create and run and is now operating in Egypt and Ghana and a few other places as well So CV basics. First and foremost, the good, the bad and the ugly. You don't need your age, you don't need your full address anymore. Please do not have ilovedogs at gmail. com as your email. Create a professional one and use it, much easier. Some of the good things, stick to one font where you can. Headings, subheadings is a brilliant use as well.
Simply use your location. If you're in London, just put London. If you're in Porto, put Porto. And as I mentioned already, don't have any dodgy email addresses. Top of your CV, so this is all personal advice and this is my opinion, so everyone's is different. But at the very top, clearly your name and your title, where you're from, big one, add any external links. So link your LinkedIn, use your GitHub as well a short bio, this can be to eliminate certain questions, but who are you? How many years of experience do you have? And also what are you looking to do? So for example, I am looking to be a senior developer to coach and mentor or I am looking for a role where I can further develop my career.
Just dropping that, you want to start banging the drum about what you do, so your key skills, Python, Django for your front end, highlight some of those More DevOps, whatever, highlight those as well. Next under the key skills section is employment history. You can read this as well, but firstly title, company, and your time frame that you've been there clearly go down in order of date, so most recent first. On the right hand side so you'll see the other things that I mentioned. Add kind of your experience of what have you been doing, what have you been developing, have you had responsibilities, coaching, mentoring other people as well? A key thing as well, just to make things stand out, is highlighting the tech stack again.
So you've already had key skills. By highlighting the key skills again, you're reaffirming to the person reviewing the CV that you have got experience in that If companies use ATS automated systems, they might just you apply here, it downloads the CV. If you're not listing it enough, you could be being missed out. So it's just a key little tip. Clearly, educations and achievements. If you've done a code academy, highlight it, add it. If you've done the Bachelor's, Master's, PhD, add what it is, add a thesis, it could be relevant to the person that's reading your CV and it might build a bit of rapport Any community involvement, you are all here. Thank you for coming clearly
but also add it in your CV. You like to attend conferences where you learn it's self-development. It's going to help improve you and it certainly looks good when you're reading a CV as well. Personal projects. Again, if you're junior and you don't have much career history experience, this is a great chance for you to advertise what you have done. So whether it's you've built a searching tool for the most recent football results, I'm a football fan Highlight what it is, what it's called, what you've done, and then your tech stack for the personal project. List about two or three, you don't need to add loads, but that will be, like I say, reiterating your experience Big one be personable.
Please do not be like every other person. It's gonna be something that helps you build rapport with that person That is all from me. I did write an article. If you want to read it or any of the stuff that we do at Foxley, scan that. But thank you very much. I'm around for questions later.
Speaker 1
Okay, so
14:59 Multiple Databases with Django
Speaker 5
Before I begin, I just wanna take a moment and thank the all the organizers and volunteers who made this conference possible. So just a round of applause. Alright, so I want to talk about how can you use multiple databases with Django So it's kind of a s obscure part of Django, but it's very interesting as well. So my name is Kadir Aziz. I work in a broker company we're based in Germany, but we also have other branches in other countries as well. So If you want to check, you can that's the link. So the first question is why multiple databases? So why we need multiple databases?
So You probably don't need it. It depends on the on the use cases. Especially if you're a small to mid-sized company, you probably don't need multiple databases. One database works just fine for you but if you're scaling up and growing, so is your data is growing. So you probably need to consider maybe adding a new database that could somehow make your app a bit more performant. I just listed a few reasons that why you need to do it. It's not really the only reasons but it also depends on the kind of architecture of your app as well. So for example
if you want to separate your read and write theories you probably have a lot of heavy read queries you probably want to redirect them all of them into a separate read applique so that's one use case The other use case could be you have a legacy system and you want to somehow upgrade it and in the process you don't want to really have any downtime, so you could also use like multiple databases. So the ne the new one will have a new database or the legacy system will use still use a legacy database. And also for the compliance and security reasons If you have a like a payment app, maybe you want to keep the payment part in a separate in a secure databases, or also
maybe for some compliance reason you don't want to keep your leave your keep your customer data in a specific region. So that's also a comp and also geographical distribution so possibly it's not really a good reason but you can consider if that that really makes sense for you then okay let's say like if you have any of these situations, so how can you do it? Like how can you integrate multiple databases in your Django? The good news is it's really simple in Django and it's straightforward. You just need to be very add a very minimal code to accommodate this change. So the first thing
I hope it works. Yes. So the first thing that you need to do is you can add your database connection in the in the setting that's that pie. So you can have multiple databases, but for example, as a just as an example, I have a read replica and I say I have a legacy database. So just for an example so what else do you need? You need a router. So a database router is a very simple class. It has just four classes, sorry, just four functions. It's just one for the It is four and then one for the reading. So if you want to redirect all your read queries to a specific database, you can specify that in that function if you want to redirect all the queries in
in another database, that's that's also a function and you can return that database there. Allow relationship so there is a small caveat there. Django does not support cross-relationship the cross-database relationship. So Because for good reasons because it's gonna get more complex if you do it. But if you wanna really do it there are way of there are way of around d to doing it. And also the other port is allow migrations. Do you want to only keep migrations in one database or you want to have migrations and run in multiple databases? But that's also something that you can configure you need one more thing and then you're ready to go. You need to register your router into your setting.
So and then you're ready to go. So you no other work and just ready to launch your app. And that's why Django is really a framework for people who are with deadlines or perfectionists for deadlines. I'm not really sure about perfectionists but so one last thing. So that that setting the router that I said is also work, but you can also manually select your databases. So that's also and that's it. Thank you.
20:16 Grafana OnCall with Django
Speaker 6
My name is Matthias. I work at Grafana. Particularly in the Grafana on call team. And I want to tell you a little bit how we use Django, specifically in our project. So, quick question. How many of you know or use Grafana? Nice. I expected that. Probably mostly of you know Rafana because of its task force and monitoring capabilities and all the panels, visualizations, logs, metrics and stuff. But inside Grafana itself, we are now we now have also incident response and management tools, particularly Grafana on call. How many of you know or use Grafana IRM tools?
One person. Nice. Well, let's try to fix that. I will focus on Grafano and call. There are other tools in the suite, because it's the project I'm working on and also because it's an open source Django-based project, which is also unexpected somehow for Grafano projects. Graphone call is a tool for on-call management with flexible workflows and mostly designed and oriented towards developers. So why it's interesting to talk in this context about Graphon Call? Well, because it's a somehow complex Django project running in the wild and with an architecture that you can See here, hopefully. How is how does it work?
We have monitoring systems running somewhere, maybe Grafana itself or ServiceNow, Jira or any other tool you use. We receive alerts from these tools in our Django server, Django project, that alert payload is processed and routed and grouped depending on parameters that you can define. The moment we receive the alert, we trigger a background worker, a background task, which will be handled by a salary worker. And a lot of magic will happen there. We need to Route and group the alerts, we need to start an escalation chain and notify users who are on call at that time. On the other hand This Django server also implements a Django
REST framework API, which is the one used by the mobile app, and the Grafana plugin which is running inside Grafana, so you get a UI for these interfaces. For this backend. And also we have well workers running the task who will trigger the notifications and the server will expect the updates from the third-party services also, depending on the status. So that's a quick look. Let's see if we can see all this thing working. Not so nice, but here you can see that you can set up an integration using different tools that you will allow you to receive alerts from these tools
This is an integration I set up before the call the talk, where I set up a webhook where I will receive some payload that will trigger an alert. You can define templates to indicate Jinja templates to how this alert will render when the notification is sent to different services. And you can also make complex conditions using Jinja also to define the route this alert will follow depending on the priority, the urgency, or some other parameter coming from the payload finally you have the escalation chain which defines how the different steps that the alert will follow to page the right person.
It's not really visible there, but there is a wait step and it will also trigger notification for the person on call for a particular schedule. So if we check the schedule Sorry, this is because I set up an alert to retrigger five minutes later after I started the talk. But we have done some delay. But right now is this is the schedule. I'm on call. I hope now no one else is on call at this time. I got the alert as you could hear from my phone And well, that's a quick summary. There is the notification in Slack. Let me close this. Thanks, sorry for the inconvenience.
If you want to know more, please let me know. You can follow the project in GitHub and that's it. Thank you
25:06 Joining the Fediverse with Django
Speaker 7
My name is Justin Mayer and I'm gonna tell you today about how you can join the Fediverse on your own domain with Django. So first of all, why? Why would you want to do this? One of the reasons that I like it is that well there's really two reasons. One you have more control when you have things on your own domain. If you join an instance you might find that they don't have They don't do updates, you don't get the latest features, they could have security issues, they might decide that they have other things to do with their time and they don't want to do it anymore and suddenly you have to migrate somewhere else. So you have more control The other one I like is that you have like there's branding and you know you might say like well I already have this domain for my company, for my open source project, and I want to use that domain as part of my as part of my you know identity.
So for me, I have a project called Pelican. It's a static site generator. I want to have it be pelican at getpelican. com because I already use the getPelican. com domain. So there's a couple ways you could do this. You could host Mastodon. The problem with hosting Mastodon is that if you want to do this for multiple identities it's means installing at multiple times. Mastodon only support one domain at a time. It's also quite resource intensive, particularly if you want to do search. It uses the Java-powered search that's rather heavy on RAM and other requirements. There's this great project called Takahi, where I think I have the pronunciation right. It's like a endangered bird from New Zealand, I think. And this was created by Andrew Godwin, a Django core developer, and it is a Django project, unsurprisingly.
And one of the things that I like the most about it is that it solves this problem of multi-tenancy, of being able to create as many domains as you want on a single instance without having to reinstall it a bunch of times. So I created a tool called Fortresa, and I use this to set up new web-based open source applications when I when there's something that I want to do. And so if I log in, I see this dashboard of instances that I've already created. If I want to install a new one, I see a much longer list of ones I haven't added. If I tap on Takahi, I see that this is the description of it. I say okay, I want to create my first instance. I then fill out all these different foreign fields. There are a lot of them, but there's a lot of configuration options and I want to support as many of those as I can.
Once it's up and running, we can see that here's the URL that I had entered into that form back there. Let's tap on that and see where we are. So this is what you see when you log in for the first time. And then you tap on the user thing to create your first user, you put in your email address, it says we're gonna send you an email link, you then get that link, you then tap on it to confirm, you set your password for the first time, it says your password is set. Then we log in for the first time and great, now it's time to create a new identity. But before you can do that, you have to view a domain in order to choose a domain for your identity. Well we don't have any yet, so first we have to create one. So we add a domain. Here you've got a choice to make. Do you want to use a single domain into for your whole instance but it has to be dedicated for that.
Well, for me, I already have a site, Pelican-powered site, on getPelican. com. I don't want to use that whole thing for this purpose. I want to use a separate social dot getPelicon. com for that. And so in this case I want to use the split domain strategy where one is the display domain and one is the service domain. So that's what I've done here. Once you have created your domain, you can go back to the other screen. We can now continue with creating an identity. Here I say, okay, I want you know pelican at get pelican. com We can see that we have now created that identity. And there's a couple things that I want to choose here. One is I want to hide the login. I'm the only one who's ever going to use this instance, so we don't need to see the login. And I want to have a single user profile redirect
where if you go to social. getPelican. com, it automatically redirects to the pelican at getpelican. com profile page. So we can see that our identity is created and we can then go to the client side of things because the one of the things that you see here is that mast Takahi doesn't include a web client like Mastodon does. You have to use a different client to do that. I use an iPhone app called Toot and I'm going to add a server. We're going to put in social. getPelican. com. We tap on the Takahi link below. Okay, now it's been added. We tap on it in order to see the settings area. We see the settings. We can tap the sign-in link. Then we go to start authentication. This is a rather long process as you can see Continue,
put in the details from your original user. You log in, you select your identity, you hit allow, and after being somewhat tired, you see that you now have your account and all you can now you can actually post to it So I think this is a really cool project. If you haven't joined the Fediverse and you have a domain that you want to like use for that purpose, this is a great way to do it. Thanks for listening. If you have any questions, I will be at the party and at the sprints tomorrow.
Speaker 1
Thank you so much.
30:12 Dreams for Django
Speaker 8
Can you hear me? Cool. So let's dream together for Django. So I'm Sarah from KSF. I'm a board member since yes last year and I would like to share with you some of my dreams. and hopefully we will make it someday. So I have a lot of dreams. So let's start because I don't have enough time I would like to hire more Django fellows so we will have time for doing like more feature and make more improvements So I would like also to have more money to do sponsor conferences and it would be a way to have more people who come with the opportunity grants
or more money for the organizer to make like great event like this one and a lot of better experience for attendee and organizer because it can cost a lot to just to come eat food and all the stuff like that Also, I would like to help our diversity and contribution mission. So by that like buying like missing materials in for example like computer books, stuff like that, especially for example in Africa or funding more current initiatives we have like for Django Girls or Django Not Space and maybe other if there is any And more and I'm sure you have also IDs. So this is the thing, but for that we need money for sure.
So by that there is a fundraising working group. I've done a draft for that and there is already members, but I think Django is nothing without the community, so you can join this working group if you want to help. And there is a link just below. And there is also a working group Not related to fundraising if you want to contribute related to all the things I've listed here And this is currently the goal we have for halfway through the year of front. And I don't know what will be the percentage we will have end of the year, but I truly think that you can all help or maybe friends you have or colleagues could help also.
So give back to the community and donate You can donate through the website, through GitHub sponsors. There is also the PowerShamp campaign we talked about at the beginning, so you can have like the license and all the money will be given to the DSF com DSF association and you can join the fundraising working group or be part of a working group so we can fool this art fully and make other things And that's all for me. Thank you. Wow, what a three days, eh?
33:08 PyCon Portugal in Braga
Speaker 5
It's been amazing. So I'm not talking about Django Khan. Now I'm switching hats or rather switching t-shirts and I'm gonna talk about PyCon Portugal. So as a member organizing member of PyCon Portugal. We did the first edition in 2020, leveraging it on Django Code in 2020 in Porto, and then we did it again last year in 2023. We have a goal of going through all Portuguese t cities with PyCon, bringing technology and raising awareness in these different cities. So the first PyCon Portugal was one day And we had lots of attendees. Thirty-two percent of them were Portuguese, which is amazing because it's PyCon Portugal. The rest of them comes
comes from 27 different countries. So last year we had 37 % of Portuguese attendees and a huge group of foreign attendees. So from PyCon portrol first and the second we increase from one day to Sorry. From one day to three days. And we got much more submissions, much more speakers, keynotes, grants. We tripled the money in grants So now we are organizing the third edition in Braga, another Portuguese city, which is amazing because Well it's it's up north. We are still in the north of Portugal, but we'll get
eventually we'll get into the south, no problem. So it will be on October 17 to 19 we'll have three days also talks and workshops and well
Speaker 8
there's a way to get a free ticket
Speaker 6
if you want to volunteer we'll have
Speaker 5
the usual teams like comms, sponsors, content, so engage please help us or you can apply for a grant and come to
Speaker 6
visit us. So why Braga, the next city Well, Braga is amazing because it has a unique mixture of cultural heritage, history Portuguese culture and technology
Speaker 5
is one of the cities with the most num at the highest numbers of Port foreign tech companies. We have an international nanotechnology center. So it it's great because it has a great mixture of innovation, academics. We have the University of Min over there also. and businesses. So it's a it's a great mixture. And another thing about Braga is oh sorry, it's not this one. Bottom line, it would be great to have you all in Brage in October. So please think about it with some care and hope to see you there. Okay? Thank you.