from django.contrib import admin

from .models import MaintenanceRecord, UserPreferences


@admin.register(UserPreferences)
class UserPreferencesAdmin(admin.ModelAdmin):
    list_display = ["user", "show_beta_interface", "airport_ui", "created_date", "modified_date"]
    list_filter = [
        "show_beta_interface", "airport_ui",
    ]


# Register your models here.
admin.site.register(MaintenanceRecord)

from django.contrib import admin

from .models import MaintenanceRecord, UserPreferences, HelpLink


@admin.register(UserPreferences)
class UserPreferencesAdmin(admin.ModelAdmin):
    list_display = ["user", "show_beta_interface", "airport_ui", "created_date", "modified_date"]
    list_filter = [
        "show_beta_interface", "airport_ui",
    ]


@admin.register(HelpLink)
class HelpLinkAdmin(admin.ModelAdmin):
    actions = None # disable the `delete selected` action

    list_display = ["link_key", "topic", "context", "href"]

    def get_readonly_fields(self, request, obj=None):
        if obj: # editing an existing object
            return self.readonly_fields + ("link_key", )
        return self.readonly_fields

    def has_add_permission(self, request):
        return False

    def has_delete_permission(self, request, obj=None):
        return False


# Register your models here.
admin.site.register(MaintenanceRecord)

Add entire in Admin for managing HelpLink
Add entire in Admin for managing HelpLink

An admin can _only_ modify the hyperlink associated with a HelpLink.

As a consequence, you cannot add new instances of the model nor delete
them. Only the existing HelpLinks can be modified because their
inclusion (or existence) is dependent upon the usage within the UI.

If one *must* do something to add or delete or override what is allowed
via Django Admin, they will _need_ database/SQL level access given this
current implementation.

See ATMO-1230 & ATMO-1270 for more context.

  from django.contrib import admin
  
- from .models import MaintenanceRecord, UserPreferences
+ from .models import MaintenanceRecord, UserPreferences, HelpLink
  
  
  @admin.register(UserPreferences)
  class UserPreferencesAdmin(admin.ModelAdmin):
      list_display = ["user", "show_beta_interface", "airport_ui", "created_date", "modified_date"]
      list_filter = [
          "show_beta_interface", "airport_ui",
      ]
  
  
+ @admin.register(HelpLink)
+ class HelpLinkAdmin(admin.ModelAdmin):
+     actions = None # disable the `delete selected` action
+ 
+     list_display = ["link_key", "topic", "context", "href"]
+ 
+     def get_readonly_fields(self, request, obj=None):
+         if obj: # editing an existing object
+             return self.readonly_fields + ("link_key", )
+         return self.readonly_fields
+ 
+     def has_add_permission(self, request):
+         return False
+ 
+     def has_delete_permission(self, request, obj=None):
+         return False
+ 
+ 
  # Register your models here.
  admin.site.register(MaintenanceRecord)
  
Add entire in Admin for managing HelpLink
## Code Before:
from django.contrib import admin

from .models import MaintenanceRecord, UserPreferences


@admin.register(UserPreferences)
class UserPreferencesAdmin(admin.ModelAdmin):
    list_display = ["user", "show_beta_interface", "airport_ui", "created_date", "modified_date"]
    list_filter = [
        "show_beta_interface", "airport_ui",
    ]


# Register your models here.
admin.site.register(MaintenanceRecord)

## Instruction:
Add entire in Admin for managing HelpLink
## Code After:
from django.contrib import admin

from .models import MaintenanceRecord, UserPreferences, HelpLink


@admin.register(UserPreferences)
class UserPreferencesAdmin(admin.ModelAdmin):
    list_display = ["user", "show_beta_interface", "airport_ui", "created_date", "modified_date"]
    list_filter = [
        "show_beta_interface", "airport_ui",
    ]


@admin.register(HelpLink)
class HelpLinkAdmin(admin.ModelAdmin):
    actions = None # disable the `delete selected` action

    list_display = ["link_key", "topic", "context", "href"]

    def get_readonly_fields(self, request, obj=None):
        if obj: # editing an existing object
            return self.readonly_fields + ("link_key", )
        return self.readonly_fields

    def has_add_permission(self, request):
        return False

    def has_delete_permission(self, request, obj=None):
        return False


# Register your models here.
admin.site.register(MaintenanceRecord)
