0๐
โ
So I had a friend that fixed it for me by creating the following form:
class auditForm(ModelForm):
class Meta:
model = datas
fields = '__all__'
def __init__(self, *args, **kwargs):
super(auditForm, self).__init__(*args, **kwargs)
self.fields['country'].disabled = True # Makes the field un-editable
self.fields['associate_resolve_date'].disabled = True
self.fields['QA_Comments_on_Associate_Action'].widget = forms.Textarea(
attrs={'class': 'form-control', 'style': 'height: 100px'}) #Sets the size of the widget
for field in self.fields:
print(field)
self.fields[field].required = False
if field != "qs_login" and field != "Status" and field != "associate_resolve_date" and field != "QA_Comments_on_Associate_Action":
self.fields[field].widget.attrs['class'] = "form-control"
So for some reason this type of form managed to do the trick, only part i didnt understand was this:
for field in self.fields:
print(field)
self.fields[field].required = False
if field != "qs_login" and field != "Status" and field != "associate_resolve_date" and field != "QA_Comments_on_Associate_Action":
self.fields[field].widget.attrs['class'] = "form-control"
I hope this is somewhat useful to anyone.
๐คKing
1๐
my blog project update method
def update(request, slug):
if not request.user.is_authenticated:
raise Http404()
blog = get_object_or_404(Blog, slug=slug)
form = BlogForm(request.POST or None, request.FILES or None, instance=blog)
if form.is_valid():
form.save()
messages.success(request, "Blog Updated")
return HttpResponseRedirect(blog.get_absolute_url())
context = {
"title": "Blog",
"form": form
}
return render(request, 'blog/create.html', context)
i hope will guide you
django blog project
๐คmstgnz
- [Answered ]-Automatic set/update fields in Django
- [Answered ]-Use validation to prevent duplicate file _name_ being uploaded
- [Answered ]-How to follow the redirct and test again in test script
- [Answered ]-Site on localhost not displaying image
- [Answered ]-Rendering/Raising A Validation Error on an HTML Template in Django
Source:stackexchange.com