Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
Django Admin: Widgetry & Witchery
Search
Sponsored
·
SiteGround - Reliable hosting with speed, security, and support you can count on.
→
Pamela Fox
August 31, 2012
Technology
1.6k
4
Share
Django Admin: Widgetry & Witchery
Why we chose to use Django admin, and how it worked, and, well, how it didn't work.
Pamela Fox
August 31, 2012
More Decks by Pamela Fox
See All by Pamela Fox
Enterprise AI in 2025?
pamelafox
0
330
Fast-track your AI app development with GitHub and Azure
pamelafox
1
210
GitHub Universe: Evaluating RAG apps in GitHub Actions
pamelafox
0
520
Learn Live: Creating a Website using GitHub Copilot
pamelafox
1
290
O'Reilly Superstream: Building a RAG App to Chat with Your Data
pamelafox
1
440
AI Tour Mexico: Production-ready RAGwith Azure AI Search
pamelafox
1
390
AI Tour Mexico: Securing AI Apps on Azure
pamelafox
0
830
RAGHack: Kickoff and RAG 101
pamelafox
1
880
RAGHack: Building RAG apps in Python
pamelafox
1
490
Other Decks in Technology
See All in Technology
[OpsJAWS 40]リリースしたら終わり、じゃなかった。セキュリティ空白期間をAWS Security Agentで埋める
sh_fk2
3
220
Oracle AI Database@AWS:サービス概要のご紹介
oracle4engineer
PRO
4
2.3k
名刺メーカーDevグループ 紹介資料
sansan33
PRO
0
1.1k
レビューしきれない?それは「全て人力でのレビュー」だからではないでしょうか
amixedcolor
0
300
AI バイブコーティングでキーボード不要?!
samakada
0
350
JEDAI in Osaka 2026イントロ
taka_aki
0
280
60分で学ぶ最新Webフロントエンド
mizdra
PRO
34
18k
Introduction to Sansan, inc / Sansan Global Development Center, Inc.
sansan33
PRO
0
3k
CloudSec JP #005 後締め ~ソフトウェアサプライチェーン攻撃から開発者のシークレットを守る~
lhazy
0
230
AgentCore×VPCでの設計パターンn選と勘所
har1101
3
250
AWS Agent Registry の基礎・概要を理解する/aws-agent-registry-intro
ren8k
2
350
EBS暗号化に失敗してEC2が動かなくなった話
hamaguchimmm
2
180
Featured
See All Featured
Utilizing Notion as your number one productivity tool
mfonobong
4
290
The Pragmatic Product Professional
lauravandoore
37
7.2k
Skip the Path - Find Your Career Trail
mkilby
1
110
How to make the Groovebox
asonas
2
2.1k
Become a Pro
speakerdeck
PRO
31
5.9k
Mobile First: as difficult as doing things right
swwweet
225
10k
Put a Button on it: Removing Barriers to Going Fast.
kastner
60
4.2k
Ethics towards AI in product and experience design
skipperchong
2
250
BBQ
matthewcrist
89
10k
Fantastic passwords and where to find them - at NoRuKo
philnash
52
3.6k
Agile Leadership in an Agile Organization
kimpetersen
PRO
0
130
Chrome DevTools: State of the Union 2024 - Debugging React & Beyond
addyosmani
10
1.1k
Transcript
Django Admin Widgetry & Witchery Pamela Fox @pamelafox Thursday, August
30, 12
Coursera: What we do Thursday, August 30, 12
Our Backend Thursday, August 30, 12
Why We Need Admin Thursday, August 30, 12
Why Django Admin? Creates forms for adding/editing/searching models Restricts fields
based on admin roles Thursday, August 30, 12
How Django Admin Works https://docs.djangoproject.com/en/dev/ref/contrib/admin/ from django.contrib import admin from
app import admin from app.courses.models import Course from app.courses.forms import CourseAdminForm class CourseAdmin(ModelAdmin): base_model = Course restrict_fields = ['instructors', 'teaching_assistants', ] form = CourseAdminForm fieldsets = [ (None, { 'fields': [ 'name', 'topic', 'active', ] }), ('Dates', { 'fields': [ 'start_date', 'end_date', 'start_date_string', 'duration_string', ] }) ] admin.site.register(Course, CourseAdmin) Thursday, August 30, 12
...And a few words on how it doesn’t work. Thursday,
August 30, 12
☹: The Look & Feel != Thursday, August 30, 12
Solution: Twitter Bootstrap https://github.com/gkuhn1/django-admin-templates-twitter-bootstrap Thursday, August 30, 12
☹: The Default Widgets BooleanField CharField ChoiceField TypedChoiceField DateField DateTimeField
DecimalField EmailField FileField FilePathField FloatField ImageField IntegerField IPAddressField GenericIPAddressField MultipleChoiceField TypedMultipleChoiceField NullBooleanField RegexField SlugField TimeField URLField ComboField MultiValueField SplitDateTimeField ModelChoiceField ModelMultipleChoiceField Thursday, August 30, 12
Solution: Custom Widgets WysiHTMLEditor TransloaditUpload UniqueShortName NumberField NumberRangeField AutoCompleteTextInput Thursday,
August 30, 12
Custom Widgets class NumberField(HiddenInput): class Media: js = ( settings.ADMIN_MEDIA_PREFIX
+ 'js/numberfields.js', ) def render(self, name, value, attrs=None): input = super(NumberField, self).render(name, value, attrs=attrs) final_attrs = self.build_attrs(attrs) units = final_attrs.get('units', '') html = u""" <div class="number-field"> %(input)s <input type="number" min="1" class="number-range-field-num input-mini"> <span class="number-range-field-units">%(units)s<span> </div> """ % {'input': input, 'units': units} return mark_safe(html) admin/common/widgets.py: from django.forms import ModelForm from app.common.widgets import NumberField class CourseAdminForm(ModelForm): class Meta: widgets = { 'duration_string': NumberField( attrs={'units': 'weeks'}) } course/forms.py from app import admin from app.courses.models import Course from app.courses.forms import CourseAdminForm class CourseAdmin(ModelAdmin): base_model = Course form = CourseAdminForm course/admin.py Thursday, August 30, 12
☹: Default Save Options != Thursday, August 30, 12
Solution: Horrible Hacks var topicPageRegEx = /\/topics\/topic\//i; var isTopicPage =
topicPageRegEx.exec(window.location.href); if (isTopicPage) { var previewHosts = {'admin': 'site', 'admin.coursera.org': 'www.coursera.org'}; var previewUrl = 'http://' + previewHosts[window.location.host] + '/course/' + $ ('input[name="short_name"]').val(); var $previewUrl = $('<input type="hidden" name="_previewurl">').val(previewUrl); var $previewButton = $('<input type="submit" name="_saveandpreview" value="Save and Preview" class="btn btn-info">'); var $saveButton = $('.form-actions input[name="_save"]') $saveButton.after(' ').after($previewButton) .after(' ').after($previewUrl); } templates/admin/change_form.html if "_saveandpreview" in request.POST: return HttpResponseRedirect(request.POST['_previewurl']) admin/options.py Thursday, August 30, 12
In conclusion... Thursday, August 30, 12
Our Future Admin Stack? https://github.com/PaulUithol/backbone-tastypie https://github.com/joshbohde/django-backbone-example Thursday, August 30, 12