2023-10-24 12:55:14 +00:00
|
|
|
from django.contrib import admin
|
|
|
|
|
2024-01-26 06:49:03 +00:00
|
|
|
from .emails import make_candidate_email
|
2023-10-24 12:55:14 +00:00
|
|
|
from .models import Candidate, Comment
|
|
|
|
|
|
|
|
|
|
|
|
class CommentInline(admin.TabularInline):
|
|
|
|
model = Comment
|
|
|
|
fields = ['user', 'message']
|
|
|
|
extra = 0
|
|
|
|
|
|
|
|
|
|
|
|
@admin.register(Candidate)
|
|
|
|
class CandidateAdmin(admin.ModelAdmin):
|
2023-10-30 22:31:28 +00:00
|
|
|
list_display = ['name', 'vendor', 'device', 'release_date', 'ordering']
|
|
|
|
list_editable = ['ordering']
|
2023-10-24 12:55:14 +00:00
|
|
|
fields = [
|
|
|
|
'name',
|
|
|
|
'slug',
|
|
|
|
'vendor',
|
|
|
|
'device',
|
|
|
|
'release_date',
|
|
|
|
'source_url',
|
|
|
|
'binary_url',
|
|
|
|
'description',
|
|
|
|
]
|
|
|
|
inlines = [CommentInline]
|
|
|
|
prepopulated_fields = {'slug': ['name']}
|
2024-01-30 12:19:42 +00:00
|
|
|
view_on_site = True
|
2024-01-26 06:49:03 +00:00
|
|
|
|
|
|
|
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()
|