I have model form and I need to have one of the fields be read only until after it's saved. I haven't figured out a good way to do this, and below is what I have in my admin.py.
class RequestForm(forms.ModelForm):
trac = forms.URLField(min_length=400, required=False)
impacted_users = forms.ModelMultipleChoiceField(queryset=Group.objects.all(), widget=forms.CheckboxSelectMultiple)
formfield_overrides = {
}
class Meta:
model = Request
class RequestAdmin(admin.ModelAdmin):
form = RequestForm
list_display = ['id', 'title', 'priority', 'requestor', 'status']
list_filter = ['requestor', 'priority', 'impacted_users']
actions = [complete]
class Media:
js = (
'/media/js/jquery.js',
'/media/js/hide.js',
)
def save_model(self, request, obj, form, change):
instance = form.save(commit=False)
instance.requestor = request.user
instance.save()
form.save_m2m()
return instance