Ad

Saving Data Form In Django Without Editable Property For Admin-django

I want to save the data of a form that user submit. But I don't wanna the admin be able to edit those data at all. I tried the readonly_field stuffs, but that didn't work.

my models.py:

class User(models.Model):

first_name = models.CharField(max_length=100)
country = CountryField()

my admin.py:

from django.contrib import admin
from .models import User

admin.site.register(User)

class MyAdmin(admin.ModelAdmin):
          readonly_fields=('first_name', 'country')
Ad

Answer

You have to add class MyAdmin also into the User for that to work .

from django.contrib import admin
from .models import User
    class MyAdmin(admin.ModelAdmin):
              readonly_fields=('first_name', 'country')
    admin.site.register(User,MyAdmin)
Ad
source: stackoverflow.com
Ad