36 lines
953 B
Python
36 lines
953 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',
|
|
'description',
|
|
]
|
|
inlines = [CommentInline]
|
|
prepopulated_fields = {'slug': ['name']}
|
|
|
|
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()
|