[Django]-How to use Field.disabled in Django

7👍

You can disable your slug field the __init__ method:

class CreateArticle(forms.ModelForm):
    class Meta:
        model = models.Article
        fields = ['title', 'body', 'slug', 'thumb']

    def __init__(self, *args, **kwargs):
        super().__init__(*args, **kwargs)
        self.fields["slug"].disabled = True
        # Or to set READONLY
        self.fields["slug"].widget.attrs["readonly"] = True
👤NKSM

Leave a comment