Hidden gems of Django Admin with Maxim Danilov

This video features Maxim Danilov at DjangoCon US 2022 in San Diego, California, USA.

Hidden gems of Django Admin with Maxim Danilov
0:45:41
Published November 3, 2022
244 views

In my presentation, I will talk about how powerful django.contrib.admin really is.

This talk was presented at: https://2022.djangocon.us/talks/hidden-gems-of-django-admin/

LINKS:
Follow Maxim Danilov 👇
On Twitter: https://twitter.com/danilovmy

Follow DjangCon US 👇
https://twitter.com/djangocon

Follow DEFNA 👇
https://twitter.com/defnado
https://www.defna.org/

Summary

Maxim Danilov shows how to extend Django’s built-in admin using features and extension points that are often undocumented. He demonstrates flexible inline rendering, nested inlines, custom many-to-many handling, autocomplete fields, related-widget permissions, and optimistic locking for concurrent edits, while warning that some techniques rely on internal APIs. His main argument is that developers should first inspect and reuse Django’s existing admin machinery instead of rewriting large amounts of code or reaching for separate admin packages.

Key takeaways

  • ModelAdmin instances are reused across requests, so isolating per-request state can improve correctness and performance.
  • Read-only fields can serve as insertion points for rendering inlines inside an admin form, including nested inline structures.
  • Proxy models and custom managers or descriptors can work around limitations in Django’s many-to-many fields and autocomplete behavior.
  • Django’s hard-coded related-widget controls can be influenced through permission methods or form-field customization, though a cleaner override point would be useful.
  • Admin log entries can provide a migration-free basis for detecting stale edits when multiple users change the same object.
  • Many seemingly missing admin capabilities already exist in Django’s code, so reading the framework and reusing its internals can reduce custom code.

Summarised automatically from the transcript.

Transcript

5,130 words · auto-generated Show

Automatically transcribed, so expect mistakes in names and technical terms.

0:20

Speaker 1: Hello, my name is Maxim and uh right now I want to tell you about hidden games in Django Contrib admin model. This is a continue of my talk from uh Django con uh This is part two and I want to go deeper in this part of my talk. A little bit uh about me. I'm owner from small company uh from Austria, a company named uh WebSoft And uh it's a small team of developers. Uh we I work with Django Science 2013 and Size Science 2015. We uh

1:06

Speaker 1: me and my team we work mostly with Django Contrip Admin. Special thanks for my team who uh support this presentation. Anastasia Sen created uh slides for this presentation. Uh thank you Anastasia. Uh Pavel Pelikin is our senior developer. He checked all my crazy ideas. And Martin Achenreiner is our uh in intern. He tested that all. My goal, I want to create user-friendly uh admin-based uh uh admin panel based on Django Contrib admin. How is it possible? I try to do it uh uh s uh already seven or eight years.

1:52

Speaker 1: And before I go deeper, I want to do a small re recap of part one of my talk. It was previously on Jange Kon. EU 2022. At first I uh I show how we can uh use better way uh to register a site admin config We can do it normally, it is not uh documented. Uh after that uh I uh tell about uh how we can use admin site registry and how all of our site admins can be registered automatically. We should not change

2:37

Speaker 1: um URL dispatcher anymore uh with the uh small lines. After that I uh cover uh about problem in resolve function in Django If we use multiple admin size sites possibility. Problem also I provide a solution of problem. We should always use site admin namespace. everywhere and of course I understand the uh default jungle templates uh in uh um uh jungle control admin they should be overridden Also, I show how we can use

3:22

Speaker 1: permission based access to uh admin URLs And there I use special function from Django user has perm. This function help us to check really uh permission from a user. Don't matter if the super user or a normal uh manager, uh I check only permission, not checkbox from model. After that, I uh presented model admin autoregistry. This is an example from uh existed code. uh this uh model admins uh already registered and I don't import nothing. Low code, low imports, uh

4:08

Speaker 1: low bugs. It's better than uh manually. And uh also I can say if I start every new project in uh Django The first code snippet which I uh copy paste as a model admin auto registry snippet. Um after that I 've cover how we can take back the control or in our project and how we can uh control order of registered model admin list on their admin sites and I open the big problem in DjangoCantrip admin: every model admin is singletone. It means for every request

4:54

Speaker 1: we work with the same instance. And this is a big problem in compare these um generic class-based views. Uh generic class-based view for every request Created a new instance and we can use this instance like container for our data. But it not works normally, it not completely works in model admin contrib. And I tell how in seven lines we can avoid this problem and after that we can um uh cache results of uh method calls and we can improve uh speed of uh our uh admin site. More uh we can achieve more than 170%

5:41

Speaker 1: faster than before. Yeah, we can make model admin faster than light. After that I show uh how we can use model admin uh in model admin action uh standard generic class based view as is really pretty in cute uh possibility uh we can after that use inheritance and we uh it is really scalable uh Please ask me how it works or you can see video it was published in uh internet And after that I tell what action decorator in jungle is wrong and please avoid use this decorator completely.

6:27

Speaker 1: uh they contain still yet stulner vulnerability and don't work with uh user permission and also i provide uh correct way how we can uh Use uh user permission for uh model admin action. And at least I show how we can transform our uh admin sites and full crude interfaces in admin in admin API collection to work with reactive frontend Loc uh the this is like a headless uh Django admin and for example after that I can ask uh developers from Django Rocket or Django

7:13

Speaker 1: 3 Django Uh boys, why you need to write too much code? It already exists in Django. Please try to use Django. This all you can uh find in uh internet uh by this link and This is a video. Also, you can find link on this video to full repository and two slides. After that, we go in deeper in model admin. Webisoft is creator from Vinepad. This is the biggest wine database in Europa. And what we do at work, we drink wines.

8:00

Speaker 1: every day. It can be, for example, more than 40 bottles in day in tasting. And every time if I drink more wines, I start to understand Django better. And of course I I should uh to say it here. I know probably the best chardonnay in whole world Came from California. I know. Thank you. Okay. And after the uh one day after the big tasting more than uh 20 bottles Uh I create a new model and I create in this model only two fields. Title, Slack, don't matter

8:47

Speaker 1: And after that I create two model admins. In first model admin I declare fields for admin form like a fields attribute. In second model admin, I declare fields for um uh for mod uh admin form like a field sets. After that I want to check how many fields in my form, in my admin form. And uh Unexpected uh unexpected uh I receive there only one uh field for first model admin and two fields for second model admin. Uh Houston, we have a problem.

9:32

Speaker 1: I open issue, I write problem in model admin, blah blah blah. I m uh uh uh say it's a bug. Uh answer was um issue was closed invalid and closed commentary. It's not a bug, it's undocumented feature. All what I try to uh tell in my talks, fast all these things are undocumented. And let's go to the different undocumented feature in Django Contrip admin. What we need? We need basic models. I create three models: shop, product, and image. Every product can be in shop, in uh every product can be an image, in shop

10:19

Speaker 1: also can be an image. And we need three model admin. Shop admin, product admin, image admin. And also I create two inlines, image inline and product inline. To uh show it in shop uh admin form. Uh you can see here already uh how work autoregistry. I don't think uh I don't need to think about uh uh uh uh manually register this model admin on the admin site. It works automatically. And if I start my project, it works as expected. We see at first admin form, at second, and on the third place

11:05

Speaker 1: uh inlines. And after that We go to the uh one problem flowable inlines in model admin. What if uh we have a big uh model admin form and we have more than 100 fields okay s uh usability problem But we want to put one inline somewhere in this small admin form and not behind. How it possible? Of course it's possible. How? Model admin contains a possibility like read-only field. In read-only field I can put all what I want. For example, hello San Diego.

11:51

Speaker 1: How it works? It works. Sunday on the model admin form, I can put my information And this is important. This field render it before uh um in lines which comes later. What I can do? At first I save in my model admin response and request on uh render change form. And after that, if uh com chems render for uh my read-only field, I render on this place one inline from context. That's all. I don't need to overwrite any something else.

12:36

Speaker 1: How it works? It works. I put I simply put inlines someday in admin form. And if I put save, if I if I press save uh I do nothing It's not render, it saves completely normally. I don't need any do anymore. If you try to find any solution in the internet It's really huge big many-line code solution instead of only four-line solution. But uh of course if you don't understand what I want right now to say, probably my language is not too good. Mostly I speak German. You can read this information

13:23

Speaker 1: on Medium. I have an article, and you can try to under you can you can understand it once more time. Inlines, if we try to go deeper in inlines uh from model admin Uh every inline can contain also read-only field. And I could can put uh a read-only field in inline Hello San Diego. It works like as expected. At first, uh model uh admin form, after that inline. In this inline we have

14:09

Speaker 1: and uh read-only field. And what if I take other model admin And I make this other model admin ready to render, and I take from context from other model admin one inline And I put this inline into read-only field from uh inline for our current model admin. How it works. It works the same like a flowable inline, only four lines. Uh at first I call uh I call product admin, uh there

14:54

Speaker 1: is this small uh error I should I should use uh self model instead of product admin uh don't matter And I call for example add view. After that I take uh from context uh inline And uh I render this in line with current context in current model admin form. Uh only one problem uh we uh have here we should uh have right now request and response. That's why for inline instances I should overwrite this uh function in model admin and I should

15:39

Speaker 1: through deeper information about self. Self has a small current model admin which contains right now request and response. And yeah, small uh remark. Uh I use it with this generator and uh in Django Contrib admin we have around Six hundred eighty uh for loops and only seventy uh yields or generators. It's not enough. We can match our uh we can do our model admin faster if we start to use generator. But don't matter right now about inlines in inlines and if you start to render it

16:26

Speaker 1: how it works Wow, it works. But but something strange is here. Uh there might uh add a new project uh button, a new product button. Okay And here is uh important information. Uh 50% or probably more uh uh code uh which uh prepared for us uh work with uh inlines lays in uh inline gs uh file from jungle and problem is it's wrong Sorry, but this is completely wrong. It was created in 2009.

17:11

Speaker 1: From many people it was changed. But it works not correctly. My issue was closed, Invalid, and you can say, Max Um it was not planned to do something like that, but my answer is stop when in JavaScript, I see uh one bug, for me it don't matter uh what what was planned. We have a bug, we should correct it. And also you can say Max, you uh too much uh criticize uh criticize all you do nothing for community. No. At first I write an article

17:57

Speaker 1: how nested inline works and and second we published uh uh inline JS which work for Whole line of Jenga from Jenga 1. 4 till last Janga and we have corrected this back. And also in this article, you can understand how nested inline works. Full solution contains around 21 lines. And right now I have a question to Developer uh from jungle nested admin or jungle nested. Boys, I you really need uh more than 600 lines in code. Probably we can speak about my uh about it uh after my talk.

18:44

Speaker 1: Um probably you can use something of what what already exists in Junker. And right now we can go deeper in our relations, relation fields Every inline uh to create any a any inline we need relation. And uh some problem we have if we start to use many-to-many in relation. For example, we extend our solution for product. Product can be produced in land, but probably, for example, ski, I'm from Austria. Ski we can receive from Poland, from from Slovenian, the same model, and from Vietnam. It means

19:30

Speaker 1: For product it can be free land lands uh there this product is produced. And also we have region where it was produced. And in this region probably I put one checkbox, this is a biological production or normal production. And also I want uh to create custom many-to-many uh model. Why? Sometimes Probably uh happens war in this region and product cannot come from this region in this moment, and I want to put off visibility of this region in this project. Product It happens, yeah, right now.

20:17

Speaker 1: And if I want to start to work with this model in model admin, what happens Shit happens. Uh system uh system error. Uh why? Uh we cannot use uh uh many to many field with custom uh with custom uh truth field Really? I cannot use it. No, I can I can use it. How? Um the best example is Uh I can use proxy model. I like proxy model in our projects we have more than uh really much proxy models

21:02

Speaker 1: and in uh with this proxy model for uh custom proof model I can declare like auto created model and What happens? It works. But please, you uh avoid it if you don't understand how it works It's important. It's a dirty hack to work with many to many with custom uh truth model, but if you don't understand it completely, please avoid it. But we have other problem in custom many-to-many truth model. Limit chases too don't work for

21:47

Speaker 1: custom truth model completely. Uh really it not works? Or we can do something. Um we can try to search a way to solution. What is many to many field in our model class? Many too many fields add to class one descriptor. This descriptor returns us a menu related manager. And in this menu related manager we have many additional attributes And this many-to-many manager is child class of parent class, which is

22:34

Speaker 1: data manager from our many-to-many model. It means we can override data manager from many-to-many model, and on getQuery set we can check. If this manager calls from um from uh many-to-many descriptor We can achieve fields, we can take from this field uh limit traces 2 and we can filter our result with limit traces 2. But don't forget, it's important. If you use um prefetch related, we don't break prefetch related results

23:21

Speaker 1: That's why I check before if something was prefetched, I leave it uh without changes and only uh on without prefetch it um uh many to many a related manager I uh use filter with limit choices too. It's easy, it works. I like it more than smart solution, which also exists. Smart solution also we can override many-to-many descriptor. But we cannot do it. Why? Uh many-to-many descriptor is ein hard coded in Django. Many too many field

24:06

Speaker 1: uh uh used uh many too many descriptor strictly in code. We can override it. Some there in other galaxy also exists Django and we can define descriptor class for every field. But like for example file field, but not in our galaxy. And not for many too many fields. And of course we can change it. Uh at first we should um override contribute to class for many to many field And after super we should call uh set other and we uh can set our many-to-many descriptor. I think it should by uh be by default, but who I am?

24:54

Speaker 1: I am only the developer. Uh and um What is with many-to-many descriptor? Many-to-many descriptor receive uh result, and if this result not prefetched. we can apply uh limit choices too for this result and we can work with that. Right now we use smart solution. In our project, I'm happy uh with that, but I think it should be changed in Django. I think Okay, relation field. We can go in deeper. In the related field widget wrapper

25:40

Speaker 1: Uh this related field widget wrapper was my probably first what the hell if I start to work with model admin. Okay, it was for for eight years ago and I start my model admin and I see uh behind the field uh related field some buttons Why? Why it happens? I don't see it in templates. How I can change it? Okay uh why it happens. Uh it's uh hard-coded in uh base model admin for every regulated field uh mm every every wrapper is wrapped In a related field

26:26

Speaker 1: widget wrapper. And we cannot override it. Why? It's I uh we cannot uh easy to uh change it, it's in hard coded. Okay, hardcore it again, again and again. How we can change it? In 2016, I try a solution and Uh I put uh uh loop through f full field in form and I uh set um uh set the uh uh uh deprecated uh attributes for every widget in form and some there it works some there is uh we don't need it. But probably it's wrong. If I have a form with

27:11

Speaker 1: many than 170 fields, it's work really long. It's wrong. Uh uh but you can find Jungle battery which do the same. Uh the uh I try to find any solution and Solution probably to use other model admin. This related widget wrapper check permissions from other model admins. And it means we can in uh has add the delete change permission uh methods We can put check if this method called from uh

27:58

Speaker 1: wrapper we can return false or or true. It works. But not always. Why? For uh auto-created many to many related To check permission , in Django used one special function which checked full permission, not directly change or delete or add full permission. And if I have, for example, view permission true, uh also I receive again the fall buttons in line. It's not always work. Okay, last frontier. After eight years, I came again for uh to

28:45

Speaker 1: function form field for Debbie field. I simply check name from every field and if I receive uh field there I don't want to see icons uh add change the let I change attribute for this widget. Right now this is the shortest way to work with uh related widget wrapper. But I think this is also not the correct way and we should have possibility to override this wrapper in model admin. But right now we don't have this possibility. Okay, it works. We have uh Austria and uh right now

29:30

Speaker 1: I put off uh the add and view possibility Next feature which really much asked in internet is uh bounded select We use bounded selects from Django 1. 4 till today. It works, uh it works for normal select, but right now we can use Django autocomplete, and it's funny to work with that Django autocomplete uh JSON view, not documented, uh issue closed, won't fix, it uh should not be documented, but we can use it. We use it uh also from front end uh for us. Uh one only one thing uh

30:16

Speaker 1: I need there is uh is protection uh how many requests per minute uh I I want uh to have this protection. We use it through Jungarest framework. Okay. To add autocomplete in model admin, it's easy. Documented, thank you. Uh we add autocomplete fields, we shoot the declare search fields, and it works. I'm happy. But how to change results of autocomplete? Results of autocomplete we can change in function get search results. If uh request is Ajax, uh

31:02

Speaker 1: we can uh take some um uh some get uh uh get inf information from get request and we can uh uh filter objects accordingly uh these get requests But okay, in uh uh a little bit early from Django is Ajax was removed and I put isax back for this functionality, but it's important. We don't uh I think this is a wrong way to work with that How we can do it better? Right now is it is not possible in Django , but you can ask how we do it in our project.

31:47

Speaker 1: Out of complete JSON view have a function getQuery set. and uh not function uh method and this method it's uh uh contains many lines of code you can um uh check it But uh developer who created this code probably forget about uh changeless instance which do the same. I can only ask uh uh probably you cannot check this code already exists. And if we create uh get changelist instance and if we ask query set, query set made the same. But also um get change list uh automatically

32:33

Speaker 1: uh works this uh gets uh with query string and get changelist instance made all uh met made filter for my objects automatically It means probably we should uh overwrite or change out a complete JSON view and probably we can use get changelist instance to receive the results of um uh autocomplete. But right now it's not possible directly in Django. Okay. Also we should uh give information for our select uh uh how they uh um bound that

33:18

Speaker 1: and on change from parent select we should send any information to uh to um child select In this case, land is parent select, um child is uh region select, and on change I start function search. Function search is completely easy and it contains uh try function why. Django use autocomplete uh JS and there um is um some function is really hard coded we cannot change or add any parameter in search string That's why uh function search uh should uh find um

34:04

Speaker 1: child elements and after that they uh wrap uh send uh data method in new method and add um uh some parameter which I want. Okay , little bit uh hard, but you can find it in repository and it works. How many lines I use? Two lines in Python and nine lines in JavaScript. I uh check Germany, uh, United K UK or something else. It works. And if you don't understand what I want to tell, you can uh you can uh read about it

34:49

Speaker 1: on Dev2 in my article. Sorry, it is not published yet. I don't have any time. I try to publish it on the next week. And this all uh it's perfect, but at the end Sunday we should press button save And what what we can to achieve. On the last version of Django, if we uh work with multiple manager in the same time on the same model admin and somebody adds an inline, somebody delete an inline, we can press save and we can receive

35:35

Speaker 1: this uh message. And this is a famous problem in uh jungle forms. Uh for hidden fields, we don't see uh the don't see error message. Uh of course I know how we can change it, but right now a problem not uh in uh the uh uh uh error render. Problem uh many user try to change the same objects and at the same time. And I think we should use existing Django versioning possibility. We can do it through Jenga admin log

36:20

Speaker 1: for every model which we use in admin panel We can add uh attribute log as a generic relation to log entry or to Django admin log. And we don't need any migration It's important. It works normally without migration. We can use it right now in every jungle project. After that On render change I sent in model admin form information uh about time one state of object uh was last time ch uh change uh changed uh in initial uh and after that

37:06

Speaker 1: I uh I should create one field uh field updated they contains uh my uh data from last change and on clean uh from my form I check if uh the data the same, time the same, microseconds the same. I think nobody changed this object Or I throw an uh validation error, but I made it a little bit better I don't throw error, I add error to form, and I use all. If I use all, I receive error message not in field.

37:51

Speaker 1: I received message on the top of my form. How it works? Please correct the error and after that the object was changed in this time Of course, uh for normal project we should do a little bit more, but right now as only example how we can use versioning which already exist in Django. And yeah, we can we can use many many things from Django which already existed. Like summary of my talk for today, I not cover many things which I collect in the last uh eight years in my work, but summary.

38:37

Speaker 1: The code which you want to write probably already existed in Django And if you uh think you are Django programmer, please try use Django instead Python. We have too much Python and too low Django in our project. I'm so sorry about it And of course, please try to learn Django. Never mind. It's not well documented, but it's it's perfectly thing. I love it. And uh it's it's amazing. Please

39:23

Speaker 1: take time and try to learn Janga. Read the code, read the articles to go to the conference. Make Janga not. Thank you.

39:45

Speaker 2: So we do have some time for questions. Would you like some easy questions?

39:52

Speaker 1: Okay.

39:53

Speaker 2: Your slide says not difficult ones. So I'll s I'll start off with an easy one. When are you going to publish that DevTwo article? Was it next week?

40:02

Speaker 1: Uh I hope next week.

40:03

Speaker 2: Cool. That's my one question. Has anyone else thought of a question yet? Make me read

40:09

Speaker 3: Yay. Uh thank you so much for your presentation. Um I d there's a lot of opinions in here. Um that one of which um I I'm not sure if I understand the the documentation one. I I love Django documentation. So I'm under I want to know where you think the Django documentation could be lacking and then also what we could do to improve it and how how we can move forward with that

40:42

Speaker 1: Thank you for question. I think uh Django documentation covers uh around 10% of uh of all possibilities of Django. For example, we don't have any uh documentation about uh query set query. Uh it's really huge and powerful part of Django, and of course we don't have We have only 10% uh documentation about Django Country admin or full Django Country uh collection. And I try to uh to make the world better. I write article mostly on Russian language, mostly on medium

41:29

Speaker 1: and Probably I can try also to contribute in documentation, but my English language probably should be better for it. Yeah. I hope I answer.

41:47

Speaker 2: Any other questions, Johns? Oh.

41:57

Speaker 4: Thank you, Katie. Maxim, great talk. I was interested by the example where you were nesting an inline from another admin in an inline.

42:07

Speaker 1: You want to see it.

42:08

Speaker 4: Well, uh I remember it and I I th you you explained the rendering. But what happens at the post? How do you save that inline? Because How do you save it back? So if you

42:19

Speaker 1: uh how how I can send uh results on save button. Yeah, uh answer lays in uh article. Yeah, sorry, I don't cover all, but what all we need to override at first we need override is changed. uh this method in form to give uh info what this uh inline in read only field was changed. at first and of course on uh save we should uh um uh recursive send ask for this uh field this field should be s uh saved and of course this inline came from other um other view it means on

43:06

Speaker 1: Save this inline send signal to other uh to other uh view to save yourself. It's it's really really three four line of code i i in reality. Yeah But it's completely work a worked solution on uh in article. You you can you can we use it already Please, better.

43:37

Speaker 5: Yeah, it's really interesting. Um I'm curious like kind of what your take. So I my understanding is when things are undocumented. Oh okay. When things are uh undocumented, it kind of means the developers are free to change them at will and uh there's not a guarantee of a Any kind of like API that's cons you know necessarily consistent between versions. How has your experience been uh kind of maintaining some of these solutions that may be leveraging like undocumented APIs in the Django admin uh cross versions, I guess.

44:16

Speaker 1: Uh we uh all solution which I provide right now in my talks works from Django 1. 4 Till Django 4. 1. 2. Of course, every time I need low code. Django improve yourself. That's why, for example, for Django 1. 4, I I need a little bit more code. But every every step it it's low and low and low and low. Right now for um Django action I threw away from our project a matchline of our existed solution.

45:01

Speaker 1: Why? Django had it itself. I think we can m use Django for better solution and right now we have Really good possibility from Django. Django version 4, I I I love it. It's really really a tool which which I like. Thank you for developers. Thank you.

Questions this talk answers

How can I put a Django admin inline in the middle of a large form?

Render the inline from a `readonly_fields` method. Save the current request and response during `render_change_form`, then render the inline when Django renders that read-only field; this avoids overriding the whole form.

Discussed at 11:51

How can I nest one Django admin inline inside another inline?

Render an inline from a read-only field on the current inline, passing the current model admin’s request and response into the nested inline. The speaker says the working implementation is only a few lines and supports saving by forwarding the nested form’s changes.

Discussed at 14:54

How can I use a custom through model for a many-to-many field in Django admin?

Use a proxy model for the custom through model and register an admin for that proxy. The speaker describes this as a workable but somewhat dirty hack that should be avoided unless you understand it fully.

Discussed at 20:17

How can I make `limit_choices_to` work with a custom many-to-many through model?

Override the many-to-many related manager’s `get_queryset()` and apply `limit_choices_to` when the manager was not populated by `prefetch_related()`. The talk also describes a more invasive descriptor-based approach.

Discussed at 21:47

How can I remove the add, change, and delete buttons beside a Django admin relationship field?

The shortest approach is to override `formfield_for_dbfield`, detect the field, and change the widget attributes that control those icons. Django does not currently provide a clean ModelAdmin hook for replacing the related-widget wrapper.

Discussed at 28:45

How can I filter or customize results in a Django admin autocomplete?

Customize the autocomplete view’s search-results logic, or use a `ChangeList` instance so Django’s normal query-string filtering is reused. The speaker notes that using a ChangeList directly for this is not currently supported by Django and requires changing the autocomplete JSON view.

Discussed at 31:47

How can I create dependent Django admin autocomplete fields?

Pass the parent field’s value to the child autocomplete by extending the JavaScript search request with an extra parameter, then filter the child results using that value. The example uses country and region selects and needs only a small Python and JavaScript change.

Discussed at 33:18

How can I prevent two Django admin users from overwriting each other’s changes?

Use Django’s existing admin log as a version source: include the object’s last-change timestamp in the form, compare it during cleaning, and add a top-level form error if the timestamp has changed since the form was opened.

Discussed at 36:20

How much of Django is covered by the official documentation?

The speaker estimates that the documentation covers roughly 10% of Django’s possibilities, including only a small portion of the QuerySet API and Django admin. He recommends reading the source and community articles and contributing documentation where possible.

Discussed at 40:42

How do I save a nested inline rendered inside another Django admin inline?

Override the form’s change-handling method so the outer form reports changes made in the read-only nested inline, then recursively submit the nested form for saving. Because the inline comes from another view, its save signal must be forwarded to that view.

Discussed at 42:19

How well do these undocumented Django admin techniques work across Django versions?

The speaker says his solutions work from Django 1.4 through Django 4.1.2, although older versions require more code. As Django gains features, some of his custom implementations can be removed in favor of built-in functionality.

Discussed at 44:16

Presenters

Note: We understand that names change, people change, and bodies change. We respect each individual's journey and privacy. If you have any concerns about a video or need us to remove content, please don't hesitate to contact us. We will handle your request with care and promptly address any issues.

More videos by Maxim Danilov

More videos from DjangoCon US