python - How to add extra fields using django.forms Textarea -
i newbie in django , working on pootle project.
i add bio (in textarea), interests (textarea), , profile pics (image upload). page looking this: http://pootle.locamotion.org/accounts/personal/edit/ (you might need login see page)
i have edited local_apps/pootle_profile/views.py looks this:
from django.forms import modelform, textarea class userform(modelform): class meta: model = user fields = ('first_name', 'last_name', 'email', 'bio') widgets = {'bio': textarea(attrs={'cols': 80, 'rows': 20})}
and in ""templates/profiles/edit_personal.html" "
<form method="post" action="/accounts/{{user.username}}/"> <p> <label for="id_first_name">{% trans 'first name' %}</label> {{ form.first_name }} {{ form.first_name.errors }} </p> <p> <label for="id_last_name">{% trans 'last name' %}</label> {{ form.last_name }} {{ form.last_name.errors }} </p> <p> <label for="id_email">{% trans 'email address' %}</label> {{ form.email }} {{ form.email.errors }} </p> <p> <label for="id_bio">{% trans 'bio' %}</label> {{ form.bio }} {{ form.bio.errors }} </p> <p class="common-buttons-block"> <input type="submit" class="save" value="{% trans 'save' %}" /> </p> </form>
but not show last bio textarea field on profile page. not loading form.bio. here html source:
<p> <label for="id_email">email address</label> <input id="id_email" type="text" name="email" value="sample@email.com" maxlength="75" /> </p> <p> <label for="id_bio">bio</label> </p>
i have added bio column in auth_user:
mariadb [pootle]> describe auth_user; +--------------+--------------+------+-----+---------+----------------+ | field | type | null | key | default | | +--------------+--------------+------+-----+---------+----------------+ | id | int(11) | no | pri | null | auto_increment | | username | varchar(30) | no | uni | null | | | first_name | varchar(30) | no | | null | | | last_name | varchar(30) | no | | null | | | email | varchar(75) | no | | null | | | password | varchar(128) | no | | null | | | is_staff | tinyint(1) | no | | null | | | is_active | tinyint(1) | no | | null | | | is_superuser | tinyint(1) | no | | null | | | last_login | datetime | no | | null | | | date_joined | datetime | no | | null | | | bio | text | yes | | null | | +--------------+--------------+------+-----+---------+----------------+ 12 rows in set (0.00 sec)
could see missing? suggestions appreciated!!
regards
firstly, digitalpbk says, don't manually add columns django's tables. instead, create userprofile model in own app, onetoonefield auth.user
.
secondly, add fields modelform, need define them explicitly @ form level:
class userform(modelform): bio = forms.charfield(widget=forms.textarea(attrs={'cols': 80, 'rows': 20})) class meta: model = user fields = ('first_name', 'last_name', 'email', 'bio')
finally, you'll need in view manually save field, user model doesn't know it.
Comments
Post a Comment