Saved you a click (or three): Supercharging the Django admin with actions and views

Video in TIB AV-Portal: Saved you a click (or three): Supercharging the Django admin with actions and views

Formal Metadata

Saved you a click (or three): Supercharging the Django admin with actions and views
Title of Series
Part Number
Number of Parts
CC Attribution - ShareAlike 3.0 Unported:
You are free to use, adapt and copy, distribute and transmit the work or content in adapted or unchanged form for any legal and non-commercial purpose as long as the work is attributed to the author in the manner specified by the author or licensor and the work or content is shared also in adapted form only under the conditions of this license.
Release Date

Content Metadata

Subject Area
Point (geometry) Group action Information View (database) System administrator Group action Mereology System call Computer animation Energy level Software framework Quicksort Library (computing) Physical system
Content management system Multiplication sign Chemical equation Moment (mathematics) Maxima and minima Bit Staff (military) Event horizon Entire function Event horizon Hacker (term) Canadian Mathematical Society Right angle Software framework Data structure Computing platform
Pairwise comparison Group action Observational study Inheritance (object-oriented programming) Computer file Euler angles Multiplication sign System administrator Set (mathematics) Digital signal Content (media) Group action Limit (category theory) Template (C++) Hypermedia Computer animation Hypermedia Iteration Procedural programming
Computer font Information View (database) Line (geometry) System administrator View (database) Electronic mailing list Database Mathematics Coefficient of determination Kernel (computing) Blog Website Pattern language Software framework Series (mathematics) Window
Computer font Multiplication Group action System administrator Instance (computer science) Mereology Landing page Data model Coefficient of determination Blog Endliche Modelltheorie Endliche Modelltheorie Website
Mathematics Computer font Mathematics View (database) Logic Computer configuration System administrator Password Website Endliche Modelltheorie Object (grammar) Template (C++)
Data model Mathematics Computer animation Information Blog Chain Electronic mailing list Electronic visual display
Data model Asynchronous Transfer Mode Coefficient of determination Personal digital assistant Blog Content (media) Endliche Modelltheorie Field (computer science)
Building Link (knot theory) View (database) File format Multiplication sign View (database) System administrator File format Electronic mailing list Hyperlink Field (computer science) Hyperlink Instance (computer science) Symbol table Field (computer science) Data model Coefficient of determination Uniform resource locator Digital photography Personal digital assistant Telecommunication Electronic visual display Error message
Greatest element Group action Functional (mathematics) Code Multiplication sign Electronic mailing list Instance (computer science) Open set Group action Field (computer science) Data model Personal digital assistant Query language Cuboid Electronic visual display Form (programming)
Axiom of choice Point (geometry) Boolean algebra Group action Greatest element Graph (mathematics) State of matter Code Connectivity (graph theory) System administrator Electronic mailing list Bit Instance (computer science) Dynamic random-access memory Replication (computing) Field (computer science) Mathematics Coefficient of determination Computer animation Personal digital assistant Different (Kate Ryan album) Text editor Endliche Modelltheorie Asynchronous Transfer Mode
Group action Functional (mathematics) Electronic mailing list Instance (computer science) Group action Mereology Event horizon Template (C++) Coefficient of determination Mathematics Personal digital assistant Radius Canadian Mathematical Society Chain Right angle Endliche Modelltheorie Object (grammar) Library (computing) Row (database) Directed graph
Mathematics Computer font Group action Functional (mathematics) Goodness of fit Mathematics Coefficient of determination Message passing View (database) Personal digital assistant Instance (computer science) Group action
Area Game controller Group action Functional (mathematics) Link (knot theory) View (database) Hyperlink Combinational logic Counting Bit Instance (computer science) Instance (computer science) Group action Equivalence relation Template (C++) Data model Mathematics Personal digital assistant Endliche Modelltheorie Object (grammar) Quicksort Conformal map
Data model Computer font Coefficient of determination Line (geometry) Line (geometry)
Asynchronous Transfer Mode Group action Link (knot theory) View (database) Gender Electronic mailing list Interactive television Group action Data model Data mining Mathematics Database normalization Process (computing) Computer animation Quicksort Sinc function
Computer font Group action File format System administrator View (database) Bit Line (geometry) Incidence algebra Web 2.0 Coefficient of determination Computer animation Personal digital assistant Different (Kate Ryan album) Order (biology) Quicksort
Functional (mathematics) Information View (database) INTEGRAL System administrator View (database) Bit Group action Wave packet Uniform resource locator Coefficient of determination Computer animation Personal digital assistant Endliche Modelltheorie
Pointer (computer programming) Dependent and independent variables Coefficient of determination Serial port View (database) Insertion loss IRIS-T Maxima and minima Menu (computing) Software framework Information
Coefficient of determination Mathematics Computer animation View (database) State of matter System administrator View (database) Software framework Quicksort Endliche Modelltheorie Power (physics)
Random number Functional (mathematics) Algorithm Context awareness View (database) View (database) Set (mathematics) Line (geometry) Instance (computer science) Flow separation Field (computer science) Wave packet Coefficient of determination Data management Object (grammar) Query language Pattern language Software framework Endliche Modelltheorie
Meta element Asynchronous Transfer Mode Context awareness Building Service (economics) System administrator View (database) Disintegration Set (mathematics) Client (computing) Uniform resource locator Data model Bit rate Software framework Damping Endliche Modelltheorie Website Router (computing) Context awareness Raw image format View (database) Mereology Group action System call Flow separation Computer animation Software framework Website Quicksort Router (computing) Library (computing)
Standard deviation Link (knot theory) System administrator Direction (geometry) Gender Open source Set (mathematics) Bit Group action Code Word Computer animation Repository (publishing) Website Software framework Freezing Physical system Reverse engineering
Email Group action Coefficient of determination Computer animation Demo (music) Personal digital assistant System administrator Demo (music) Combinational logic Wave packet
Coefficient of determination Disk read-and-write head Field (computer science)
Web page Group action System administrator View (database) Instance (computer science) Mereology
Code Multiplication sign Feedback Software framework Open set Flow separation
and call of the and
and OR and
IV in the room if there are becoming angry talking about actions in use in the Django admin and mostly at this is a lot of this is that we place an easy ways to customize it to get people some quick information to the other judges the it like as a sitting are admin users click so especially OWL and we're in search of talking with the other tips and tricks and libraries it might be an overloaded 1st it's gonna gonna go from 1 beginner level and we're gonna can be abstracted out and talk a little more abstract the end as but the point is that there's a lot of ways to do this to do some of the things that we need to do the and and other a lot of libraries that kind of overlap and conflict that are all kind of on the same page as so the conclusion is that necessarily part of it is to give you some tools and ideas and checks have a part also to our system suggests other ways to think about the Ivan moralistically in and provide a framework for it and that is also at the sort of 45 minutes that's another reason is going to be overlooked going a little faster than expected
and a lot of this is so have learned a lot of this by doing work at the Texas Tribune whenever 2 years the text should be and as based in Austin or non-profit nonpartisan all all-digital news organization and we we focus on Texas politics and policy I We recombination use didn't events that we also have the right to to my colleagues in the entire also here focus on these things as well about talking mark but it is this so we have a lot of that users are seen as you
desire very busy structure time they need to publish breaking news very fast but then we also do a lot of investigated features in longer stories were we want well structured data where we can now make sure that it gets presented well all the time and on every platform that were on so it's a tough balance and them we are we do it all together is called rich vanilla GenGO right now a moving looking at and moving toward the CMS framework writing a CMS out at the moment yeah all pretty much vanilla so we've have not found a lot of little tips hacks and things you can do in there and have agenda and then to to make it really fast and easy for users to publish stories a little bit about my background that
attitude for 2 years before that I was in a parental comparative media studies at MIT working procedures Digital Humanities Lab and before that I was working at a certain time iterations wiser as Belanger and I'm in there as well but I feel like a really stretches limits in the last couple of years of the 20th we found that
specialized for certain Django where is working with it I really quickly wanted to add that a couple easy but in Xi'an Aircraft quick actions we a set of little stuff that shouldn't be that hard and every time and I had at that time is an it it and have a lot of coupled files a lot of couple characters never right to me I struggled with a lot of that at that you really recently completed an admin redesigned a little that uh on just you know rescanning and we I learned a lot to give us opportunity to re-architect as some some of the ways that were doing so the and customizations so if you
think of the admin that again is a series of windows they're increasingly getting into a kernel information you need you start with that the whole dashboard site you will site and you move instead of a list you and then you move into a detailed view any movement in mind inside of that and can use that as that zooming-in as a framework for some of the checks and talk about in the stock and then at the again it should wrap it all up into a bow and talk about wife way they all have the similar patterns that we can learn from the again the inferred intention is an intention but it might overwhelm and it will be a lot of will make some sense of the and throwing allowing all 1 the with sticks
Our amusing example site it's called newshound it's a blog by dollars for dogs and about drugs and also the database of freedom dog breeds that which were scraped from the American Chemical of day and so he can following a given given back on such real backward flesh newfound there can be example there everything I'm about to show so hopefully will be quite is overwhelming and I apologize in advance they're extremely contrived examples I ran out of ideas for how to talk about dogs at
the data model that we have a new sounds and is basically we have we have the blog posts and they said that they be of post might be that might be that individual dogs and they talking about each of these dogs can be part of multiple breeds that the custom through model because the dog could be 25 % schnauzer and 75 per cent to all up and then and then each read as part of a group regroup so for instance a toy that the toy Grouper the herding dog river the terrier group again this is really just as going to start
somewhere so was really quickly the admin Satan landing page a quick thing that you can do here to make your your initial Dutch words but
a little friendlier is that to have a custom admin sites on on here on a genuine and basically and this this lets you has a couple advantages 1st of all you can customize your site Harrison scenario the over here if I can get my yeah yeah see newshound appear the top rather than just the aging administration and and then also allows to do because log templates so here in a custom additive forgot your password option that here which is something we have our are seen as so it's really handy to have this that has of insight to me really easy quick changes and and it I also personally like that it with all the admin logic into 1 model so you don't have these other discovers going on all over and across different you have a centralized place for all of here and say logic lives and when the change
was to use this is how the bulk of that we have a lot about 1 object the perceived here and here's the
basic changes you are with that largest that the blog posts and you see there's 1 article that published then there is a great headlines the yes the new is very much information others and there are a lot of problems years now and not much you can do as
so the 1st thing you can do that list display year two year chain list of this at the at any other columns you want so you your 2nd column pretty straightforward but people know this 1 the
ability to get lysis will a step further you can do a few other things so 1st of all and you can add extra fields that are actually on your model and then define in the admin and tell them this year they say what you want the content of the and the column to be so in this case our just listing all the dogs that are that have been through tag associated with this blog posts if you do this don't forget
to select later approved prefetcher related model because otherwise I will get heavy and slow very fast the i the other thing
outside of list display 1 thing we use a lot is to combine it with format and doing this format HTML this lets us put any arbitrary HTML into those columns so you don't you have you can kind of in this case for instance or doing on is where for each dialog work where radial link hyperlink to the dogs absolute URL and that uh manifest over here it's time is the kind of Odyssey but you can use get this list nicely formatted list of names and you have a link out to go see those in building up where years this is additional entity for an error I that the really easy way to visual communication rather than overloading summary with Walter attacks are a bunch of hyperlinks so symbols in there it's just text it's really easy to do and and and and makes makes it visually cleaner so I'm cheating a
little here in a time of the detail you really quickly and then go back to the interview but another way the formational as with read-only fields and really feels very similarly I if you set for in this case the photo preview and this then you put if you put in your fields will show up in the detail view and you can again but any initially 1 here so in this case are getting a preview of this dog the stockbreeder can't read that 2 key dog biscuits a new admin who like that of
yeah but back to the list you another handy check is list editable this 1 and here we'll see it as it turns this headline feel into open feel that you can just edit out from the list you so if you had a hundred of them here again at all 100 at once and then you click the Save button at the bottom and you you're all set we find that this 1 that add another button in and the whole bunch of form fields and it's not very friendly to users and stresses people out when they see it but we usually we use it it's particularly handy for cleanup sprints with the we found so for instance at the Texas you we have a lot of tag data and so it's very messy so want to the there's 1 spread worries everything about tags and so for those and a lot of fields list editable 4 at the time that we were doing the spread and that was really helpful for making and getting in there really quickly making any alterations and then and saving the need and the and ran
from displays 2 actions actions and that there must basic little admin actions allow you to easily check out certain items in a changeless and check boxes and then perform a function based on on what you checked off and in this case this code is the publishing of the check of items that you had set set them all to be published 1
thing we started to do at the Tribunal's ad make dynamic actions based on some of the choices that are in our models so in this case we have a few different states for publication you might have in draft mode in edit mode and published mode and here of this code is is it is making an action for each of those states and then manifest in the end with that this list at the bottom of actions you considered 2 draft that publish that at it it was changes in the models zooming out
even further this is really tiny components are that on even further you know we've started working on Admin Admin Nixon's action in this case and that would still use with defining that we even use define an action field that tribute on your admin model ends at that point it will added action choices for you so in this case in in that that works for either Boolean field offer choices so here for instance we have a post admin which is not setting the graph editor published and down here it's hard to read but you also have a dog admin dogs have actively anatomy for whether good or not and in this case you can set the activity to be you can set all this check diet items to be all that to be good at all them to be bad and she's done with this nice handy make sense enough to worry about our replicability I'm moving a little bit more
into the libraries and packages but those and talk about what if you want to add actions for instance for each item in you changeless you have you have your list of items and you quite yet but next at the end of each of them to do something with that individual and but this is a really handy package coding row actions and I IBC add that column for you down here in the corner you see has has dropped on all actions you click on it and you in this case that you can either redirects to delete you for that individual objects or that you can make an eagle the dogs good I guess in this 1 as it is a defining a particular action or particular URL and then it will it will do the rest for you another package that we use a lot
is called Jango object this was developed actually at the Texas Tribune by our own colleague Chris Chang it does a whole lot for us this is 1 thing it does and if they elect you put easily put chain but button then the changeless without modifying a template so you'll see that here you have this publish all edits button to show up here in the corner on this changes you and it's really just a defining any other of function here and 1 key part is this changes actions part and that led and that that's really what's that about the politics to add a button right there which initially found was was harder than it should have been to do sustainably are 1 way that we use these buttons for all our models is we we often harassing car models with actually the eyes for instance of how we think of Milton prevent right and that that's where we are who saw a lot of our data for events so we might put a sink button right there so that people can quickly to sink apart CMS in our are website with whatever's going on externally and it's pretty easy place to put it moving as further into the change
use again working on actions they have not
just changeless actions they also have change actions and the there even India I think that so in this case I use this just lets you that take that particular instance in news that uh rather than having the listwise and here we are making all the dogs good in this particular article so this article might mention a few dogs they're all automatically get the click this button and also I a it maintains a lot of the added features x message User even unique to still of the same functionality that you could do with any any you any and
in future but I wanna reiterated redirects make it really easy to add hyperlinks during the equivalent of hyperlinks without adding changing a template models so in this case but this is basically a link it's just you're you're going to a certain changes you can but you're doing it with actions and that that this is a little bit more and removes it further into the back and letters in control work I also really like this heady takes instance agrees that area becomes Rodrigo object actions which let you put it on both the change in the change of view that once the that's a handy feature In a shot to Christophe here here but because actions
are just use that under the hood you can add can confirm use cooperation diastolic agenda delete you resources this is how the combination of the 2 things that have been the 2 sort of the action and the reader and the the the link so in this case a stepping through with this publish edited action is doing you start with and so it is the 1st thing you do is it looks for a POST request it doesn't see 1 so this renders a confirmation and here's the count that the confirmation view over here just make sure that you have that you want to leave these things and the 2nd time around if you put all you to do and it's really tiny text but I have to do is put a an action-value into the post that and it will send it straight back to this year so you can use the same view to both render the have confirmation view and also process the conformation when it happens and this way you can you you get the best of both worlds and all wrapped into 1 nice function going zooming further
into in lines that we've a couple other packages that we have found that really handy here this sort of as the the first one
here are just a generic in line this has no edits and this is showing a post can have multiple dogs and you can assign them
the large-angle inline actions is that basically so we we really residing and actions which let you change specific items from the changes this is a is another layer of conception from that where you're now be able to and edit and and process things from the online view and since genuine reactions can do that so in this case but you're again I'm just getting a link to all of you redirects to the that the different resource as for the pretty needed so just just for a reference you can
also use genuine mine actions in change list so this is kind of redundant with gender interaction which sort showed earlier but I going know under the I and feature that
is looks really handy we haven't had opportunity use it at the Tribune but I was interested in and is Jagger nested admin this is developed by our friends at the Atlantic and basically in line infections and in this case uh you have of breed group so that might be like toy dogs and then than in each breed had a each breed group has multiple breeds in then each breed has multiple dogs associated that breed this admin allows you to put all 3 of those layers right in 1 view so here and you're able to edit everything about the breed group everything about the breed or anything about the dogs themselves I have but 1 and also the sorting for you that's really handy feature he of order will feel the considered as audible and then just dragon drop them that 1 warning is that would be web over querying without prefetching I'm not entirely sure how that works under the hood format for doing an incident in which is to be aware of that doing too much with and it gives you you can get really really slow the some dumb assed tug up
packages for now I'll look a little bit what we we could do next as sort of thinking about all these together all these different packages and ideas of 1 thing that I found is that
basically all of them are using this get your URLs function from the admin get Urals basically the gendered shows you can add any use any additional views to that model and then on the fly and that's a really handy idea and pretty it's pretty much work how all of these different tools and and the using are working and so we started
to hold more of our and features into mixands using get your else and specifically we are interested in how to do this at Ajax views I we want that we want a little bit more dynamic information in my obtaining information into our admins that we and we won't be able to do it so it were integrates nicely with the Django admin in this case I believe this example we are putting a preview of all the dogs that are currently trending I'm not sure what what the trending while attending but but that that you may have your writer writing about dogs you might wanna know which of the training so you know how to write about so in this case I it busily this get you also Genesis sending anything that goes the trending URL back to that training function and that's where a lot of the work happens but here I have to be using in the
dark a dog serializer from generous framework you actually treat that our response you could do it in a million her ways and and
then the but the JavaScript is looks looks a little longer it's really not very complicated and just calling API updating a container and to and
that this is sort of what end up looking like an so down here you see this is this is just the changes you over here but about it yet I this ajax driven will module that shows you 3 dogs that might be trending if you click this button over here this refresh suggestions you get 3 different dogs or maybe this and artificial and so this got me
thinking they were using Ajax view by basically this states view known by Bannard and J. guys this incredible framework for doing just that generous framework and thinking about the best ways that we could be combining the all the powers of the Django mark the jingle model admins with all the powers of dangerous framework so here I have added trending so change this the trending dog you instead of putting up but view on the admin and then here I made a
new API view that was basically getting at its it's taking what was about a timeline function injury into 3 lines and also getting all the bells and whistles that the rest framework gives you about that so that that that's a pretty handy pattern there were interested in and
once that even farther than I've been thinking about we are this so is basically moving the training algorithm into a model manager that under under the dog the dog model and then at turning it into a set of on the set I think when was so with the right pagination this assumptions exactly the same way that online that online feuded arises all declarative now there's no function really in in that field at a better separation of concerns to but the trending into the manager's wall and so this is I think this is a really a promising start to something but it has no way for instance to get into the detail view to receive the context that the model and gets at least the way that I so this
is just to to sort of finish that off this is the use of the the get Urals for this this new
set all you need to do is add that trending at URL and call the call that you know the new rolling so
yeah I think there's something here all these libraries are pointing to it the there's the combining model urging a model and then invest framework is something where increasingly doing and were curious I feel like it's a very powerful combination and we want to do more with that the i kidding is the possibility friends and getting full credit capability and on Django models I with Ajax use right the admin with all the contexts and in all the richness that the mark the Django admin provides but I think some open questions about that we aren't sure about that you how you deal with that integrate with the router and the router framework where as well as the best ways to integrate to to put the admin context into the API view sets and what's the best way to manage your friend and assets especially JavaScript your your CSS for and what you doing but more broadly we want we you know we want our skills this feels like the rates have to go we wanna and to be an API Client just like a website is just like our external services are alive it feels better architecturally so we're interested in how to work toward that we also don't so they want build custom whole django and no separate admin from scratch because we just don't have the the team for that and so
this is surrounded by a the question would why would we stick with the admin at all and inactive when it's a little bit I and I think 1 of the short answers with an 8 year old website and it's a lot of built up coding of you really hard to to do that but so busy the whole thing onto a only system but the longer answer is the word there's a lot of promise in the Django admin and you get this thing the versioning for freezing gender reversion you get things like locking watching a locking on and this standardization in the community around that just just opens a suffered a lot of really interesting possibilities especially with the directions that generous framework has been going on so we're excited were sticking with the Django admin the we we might end up as a set of standardizing it further out by putting an answer managing the CMS erectile but that's the word is excited the future possibilities on the genuine and we think that that there's there's more that could be done with it and so
I wanted to aviation shouts all the repositories there to packages that we use and here's links to them on get have and and I think I think I cover them all and I have to reiterate
this this newshounds and
that quickly and show demo just in case so that was hard to see here's the dashboard for
sounds you got breeds dogs person breed groups of you go to the post admin will only get this training dogs and refresh 0 we've got much of of his day a very interesting combination of reads there and the this does are not real
but still so a refresher let's let's refresh again just people
looking dogs for a while and then that's a suitable the features that we have in here and again we that you breed buttons used to seal of the breed I you publish all year stories connected nodes right now that's an edits of a publish this idea that confirm
VO and click and heads published and our and these 2 publications that is from the published so here's the sad editable field here so far only get dance then I had saved in a lot of things that
but if I click and here you again get the same preview the and here you see the mine action so you can see all the breed groups that hit the stock here is
part of here is the and I believe this is where see in inline actions so this is going nested admin this it will really slowly because they do not prefetch anything but this is basically where you can edit pretty much the whole admin from 1 page that's why it takes a while so all this of view so so here you have the hounds and here's the 1st on the Afghan Hound weaker Holly Holly's enough you know is is 100 % of encounter was eating so to change any of those and details trigger from the island and the this tall nested so the next 1 down for instance the American English pronounced the gun this is a really handy features so all this combined but I believe this is all about I didn't
tell about 100 me to undermine the code we really a lot of features and and that fills in a separation of concerns and stop there is not time for questions and feedback and were again not really all the way there now we have a lot of open questions especially ran an integrated framework of running right thank me so if
Fannie and she a way