One register on admin

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
from django.contrib import admin
from .models import Section, Package, Instruction, ActivePackages


class Restricted(admin.ModelAdmin):
    actions = None
    mymodel = None

    def has_add_permission(self, request):
        assert self.mymodel is not None, "No set mymodel var"
           
        if self.mymodel.objects.count() >= 1:
            return False
        else:
            return True

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


class SeccionAdmin(Restricted):
    mymodel = Section

class ActivePackagesAdmin(Restricted):
    mymodel = ActivePackages

admin.site.register(Section, SeccionAdmin)
admin.site.register(ActivePackages, ActivePackagesAdmin)

More like this

  1. Add delete button in admin cp by cschand 6 years ago
  2. easy admin registration by alia_khouri 5 years, 7 months ago
  3. Accordion changelist admin by rodnsi 4 years, 5 months ago
  4. Django admin autoregister by Mimino 5 months, 2 weeks ago
  5. Generic admin action export selected rows to excel by jordic 2 years, 6 months ago

Comments

(Forgotten your password?)