Write-Once Fields in Django Models

I have a rather difficult time trying to create a one-time field in a Django model. Ideally, I would like it to work as a final variable, although I can agree to simply prevent it from being edited with the administrator.

I know that there is a solution for read-only fields, but it also affects the add form, and I don't want the field to be read-only.

+4
source share
1 answer

Use get_readonly_fields() and return a tuple with a write-once field name if obj exists, or an empty tuple if obj is None .

http://docs.djangoproject.com/en/dev/ref/contrib/admin/#django.contrib.admin.ModelAdmin.get_readonly_fields

+5
source

All Articles