In a Django form, how do I make a field readonly (or disabled) so that it cannot be edited? - Stack Overflow

PHOTO EMBED

Sun Apr 03 2022 13:48:43 GMT+0000 (UTC)

Saved by @elzoz #django

class Item(models.Model):
    sku = models.CharField(max_length=50)
    description = models.CharField(max_length=200)
    added_by = models.ForeignKey(User)


class ItemForm(ModelForm):
    class Meta:
        model = Item
        exclude = ('added_by')

def new_item_view(request):
    if request.method == 'POST':
        form = ItemForm(request.POST)
        # Validate and save
    else:
            form = ItemForm()
    # Render the view
content_copyCOPY

dddd

https://stackoverflow.com/questions/324477/in-a-django-form-how-do-i-make-a-field-readonly-or-disabled-so-that-it-cannot