Django Form - Status

Asked

Viewed 26 times

-1

I am working on a library administration system and at this moment I am creating the logical part to realize a loan. Here is my great doubt; How to set a state for available or unavailable book within a form so that that state is displayed within a readonly form field?

Explaining better: when searching for the book using a unique code, all book information will be displayed within a read-only form, in this form there is a field for AVAILABILITY that shows whether the book is available or not. Is there a specific method to make this kind of display?

1 answer

0

You will set the disable attribute to true

The disabled Boolean argument, when set to True, disables a form field using the disabled HTML attribute, so that it is not editable by users. Even if a user tampers with the value of the field sent to the server, it will be ignored in favor of the value of the initial form data.

class ItemForm(forms.ModelForm):
    def __init__(self, *args, **kwargs):
        super(ItemForm, self).__init__(*args, **kwargs)
        self.fields['my_field'].disable = True

Browser other questions tagged

You are not signed in. Login or sign up in order to post.