38 lines
1,013 B
Python
38 lines
1,013 B
Python
from django.contrib import admin
|
|
|
|
from .emails import make_candidate_email
|
|
from .models import Candidate, Comment
|
|
|
|
|
|
class CommentInline(admin.TabularInline):
|
|
model = Comment
|
|
fields = ['user', 'message']
|
|
extra = 0
|
|
|
|
|
|
@admin.register(Candidate)
|
|
class CandidateAdmin(admin.ModelAdmin):
|
|
list_display = ['name', 'vendor', 'device', 'release_date', 'ordering']
|
|
list_editable = ['ordering']
|
|
fields = [
|
|
'name',
|
|
'slug',
|
|
'vendor',
|
|
'device',
|
|
'release_date',
|
|
'source_url',
|
|
'binary_url',
|
|
'show_download_disclaimer',
|
|
'description',
|
|
]
|
|
inlines = [CommentInline]
|
|
prepopulated_fields = {'slug': ['name']}
|
|
view_on_site = True
|
|
|
|
def save_model(self, request, obj, form, change):
|
|
send_email = obj.id is None
|
|
super().save_model(request, obj, form, change)
|
|
if send_email:
|
|
# Announce the new candidate
|
|
email = make_candidate_email(obj, request.user)
|
|
email.send()
|