Управление доступом к поддельной модели в админке Django
У меня есть следующий код в admin.py, где он создает модели. Однако, эта модель доступна любому в системе, как я могу контролировать доступ к этой модели, как к любой другой модели
class BalaceForm(admin.ModelAdmin):
def has_add_permission(*args, **kwargs):
return False
def has_change_permission(*args, **kwargs):
return True
def has_delete_permission(*args, **kwargs):
return False
def changelist_view(self, request):
context = {'title': 'My Custom AdminForm'}
if request.method == 'POST':
form = CustomerProfilesForm(request.POST)
if form.is_valid():
# Do your magic with the completed form data.
# Let the user know that form was submitted.
messages.success(request, 'Congrats, form submitted!')
return HttpResponseRedirect('')
else:
messages.error(
request, 'Please correct the error below'
)
else:
form = CustomerProfilesForm()
context['form'] = form
return render(request, 'admin/change_form.html', context)
class AccountStats(object):
class _meta:
app_label = 'onboardapi' # This is the app that the form will exist under
model_name = 'account-stats' # This is what will be used in the link url
verbose_name_plural = 'Account summary' # This is the name used in the link text
object_name = 'ObjectName'
app_config = ""
swapped = False
abstract = False
admin.site.register([AccountStatsAll],BalaceForm)