I have a django model
models.py
class Item(models.Model):
author = models.ForeignKey(User)
name = models.CharField('Brief summary of job', max_length=200)
created = models.DateTimeField('Created', auto_now=True,auto_now_add=True)
description = models.TextField('Description of job')
I would like to update the description field in a modelform using UpdateView. I would like to see the other fields (author,name etc) but want editing and POST disabled
forms.py
from django.forms import ModelForm
from todo.models import Item
class EditForm(ModelForm):
class Meta:
model = Item
fields = ['author', 'job_for', 'name', 'description']
urls.py
urlpatterns = patterns('',
# eg /todo/
url(r'^$', views.IndexView.as_view(), name='index'),
#eg /todo/5
url(r'^(?P<pk>\d+)/$', views.UpdateItem.as_view(), name='update_item'),
)
views.py
class UpdateItem(UpdateView):
model = Item
form_class = EditForm
template_name = 'todo/detail.html'
# Revert to a named url
success_url = reverse_lazy('index')
I have looked at the solution suggesting form.fields['field'].widget.attrs['readonly'] = True
but I am unsure where to put this or how to implement