non DB related fiels in model to appear in a form

18 views
Skip to first unread message

wigm...@gmail.com

unread,
Jun 1, 2015, 11:03:14 AM6/1/15
to django...@googlegroups.com

Hello all,

how can I add a string in the model that would appear in the output form exactly
on the position from the model as text e.g. in a Paragraph. Is it possible to
create a non DB related Field in models for that?

Example how I would like it to be :

in models.py

class Example(models.Model):
    Name                       = models.CharField(max_length=100,blank=True,null=True)
    # Now a field that needs no DB representation
    Question_TIW         = models.TextInAParagraphField(verbose_name='Some informational Text')
    # or assign verbose_name later in view
    Ans1_OKH               = models.BooleanField(default=False)
    Ans2_OKH               = models.BooleanField(default=False)
    Ans3_OKH               = models.BooleanField(default=False)

Result should be a Form

with a Name input,
followed by 'Some informational Text',
followed by Select Buttons to click
followed by a submit button

kind regards
Reiner

Chris Strasser

unread,
Jun 2, 2015, 6:18:06 PM6/2/15
to django...@googlegroups.com
hi Reiner I think what you want to do is controlled in the view not the model.

in your view do something like this:

context = {'form':form, 'infotext': "some informational text"} 
             return render(request,'form.html', context)


then in your template you can refer to it as follows:

{{form.name}}

{{ infotext}}

{{form.Ans1_OKH}}
{{form.Ans2_OKH}}
{{form.Ans3_OKH}}

hope that helps ...
Reply all
Reply to author
Forward
0 new messages