Search code examples
pythondjangoadmin

How can create model that couldn't be changed by admin?


I need to create Django model that couldn't by admin, but he should be avialable to see it. It's content will be input from site. How can I do it?


Solution

  • Designate that it should be read only

    In your Model Admin, you can specify that certain fields are not to be changed.

    class ProfileAdmin(admin.ModelAdmin):
        readonly_fields = ('source', 'campaign')
    

    Just put that in your admin.py and then when you got to register your site, use this:

    admin.site.register(Profile, ProfileAdmin)
    

    instead of what you are probably currently using, which would be

    admin.site.register(Profile)