website/conservancy/usethesource/admin.py

46 lines
1.2 KiB
Python
Raw Normal View History

from django.contrib import admin
from .emails import make_candidate_email
2024-07-29 13:44:40 +00:00
from .models import Candidate, Comment, SourceOffer
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()
2024-07-29 13:44:40 +00:00
@admin.register(SourceOffer)
class SourceOfferAdmin(admin.ModelAdmin):
list_display = ['time', 'vendor', 'device']
fields = ['time', 'vendor', 'device', 'photo']
readonly_fields = ['time']