Like a DB but with with a mouse!
ELAD SILBERRING
Master of code, God of bits
Let's see some screenshots
Home of all apps and their models
(Based on permissions)
All our instances in 1 page!
Lets Break PROD!
Do you like color?
# PRESENTING CODE
from django.contrib import admin
from myapp.models import Author
admin.site.register(Author)
# USING DECORATORS
from django.contrib import admin
from .models import Author
@admin.register(Author)
class AuthorAdmin(admin.ModelAdmin):
pass
# PRESENTING CODE
@admin.register(Author)
class AuthorAdmin(admin.ModelAdmin):
list_display = ["name", "birth_date"]
# to show all => list_display = BookAdmin._meta.get_all_field_names()
### what else? ###
@admin.register(Author)
class AuthorAdmin(admin.ModelAdmin):
list_display = ["name", "birth_date", "ratings_count"] # ratings_count is a model function
@admin.display(empty_value="N/A")
def ratings_count(self, obj):
return self.google_ratings + self.kindle_ratings
# PRESENTING CODE
# MODEL
class Author(models.Model):
name = models.CharField(max_length=100)
title = models.CharField(max_length=3)
birth_date = models.DateField(blank=True, null=True)
# ADMIN -> admin.py code
class AuthorAdmin(admin.ModelAdmin):
fields = ["name", "title"]
## OR ##
class AuthorAdmin(admin.ModelAdmin):
exclude = ["birth_date"]
what can go wrong?
Inline Edit
@admin.register(Book)
class BookAdmin(admin.ModelAdmin):
list_display = ["book", "year", "rank"]
inlines = ["book", "year", "rank"]
Inline Edit
@admin.register(Shelf)
class ShelfAdmin(admin.ModelAdmin):
list_display = ["book", "year", "rank"]
list_editable = ["book", "year", "rank"]
actions = ("uppercase",)
@admin.action(description='Make selected books uppercase')
def uppercase(modeladmin, request, queryset):
for obj in queryset:
obj.book = obj.name.upper()
obj.save()
# what's this??
messages.success(request, "Successfully made uppercase!")
Lets Go PM!
This can be a custom field - only dropdown
# PRESENTING CODE
from django.contrib import admin
class FlatPageAdmin(admin.ModelAdmin):
fieldsets = [
(
None, # title
{
"fields": ["url", "title", "content", "sites"],
},
),
(
"Advanced options",
{
"classes": ["collapse"],
"fields": ["registration_required", "template_name"],
},
),
]
# PRESENTING CODE
Multiple Admin
Sites For 1 App!
Connect To
Multiple DBs!
Run tests from UI!
by flow type?
Rerun task
merge data