So as the title says, I am trying to shrink the widths of a couple of fields on my Django page. It is mainly CharField
, DecimalField
and IntegerField
if that makes any difference.
Here is an example of one of the fields
title = models.CharField(max_length=200)
I have found others have used widgets but not able to get it work, both because I am uncertain how to use these, and maybe also because those examples all seemed to be using django.forms.CharField
. Here is a link to such an example. I tried such an example like this:
title = models.CharField(max_length=200, widget=forms.Textarea(attrs={'cols': 10, 'rows': 20}))
but also:
title = models.CharField(max_length=200, widget=models.Textarea(attrs={'cols': 10, 'rows': 20}))
with import django.db.models
and import django.forms
Here are my updated files:
models.py
class ChemRun(forms.Form):
title = forms.CharField(max_length=50, widget=forms.TextInput(attrs={'style': 'width: 400px;' }))
created_date = forms.DateTimeField(initial=timezone.now)
status = forms.CharField(max_length=20, initial="In queue")
forms.py
class ChemRunForm(forms.Form):
class Meta:
model = ChemRun
exclude = ('created_date', 'status')
views.py
@verified_email_required
def create(request):
if request.POST:
form = ChemRunForm()
f = form.save(commit=False)
f.owner = request.user
f.save()
data = form.cleaned_data
initiate_run.delay(data)
return HttpResponseRedirect('/accounts/profile')
else:
form = ChemRunForm()
args = {}
args.update(csrf(request))
args['form'] = form
return render_to_response('interface/newrun.html', args, context_instance=RequestContext(request))