python - register django textarea widget in admin -
i want register standard django textarea widget
admin. i'm little confused this, because in documentation have modeladmin.formfield_overrides
example, don't want override it, want register it. there simple way of doing registration or should override , make custom widget out of it?
models.py:
from django.db import models django_countries.fields import countryfield import datetime # create models here. class contactform(models.model): first_name = models.charfield(max_length=150) last_name = models.charfield(max_length=150) email = models.emailfield(max_length=250) mobile = models.charfield(max_length=32, blank=true) timestamp = models.datetimefield(default=datetime.datetime.now) birthday = models.datefield(null=true) move_in_date = models.datefield(null=true) move_out_date = models.datefield(null=true) country = countryfield() def __unicode__(self): """todo: docstring __unicode__. :returns: todo """ return self.email class meta: ordering = ['-timestamp']
forms.py:
from django.forms import modelform, extras .models import contactform django import forms crispy_forms.helper import formhelper crispy_forms.layout import layout crispy_forms.bootstrap import tabholder, tab django_countries.widgets import countryselectwidget import datetime def get_move_date_field(): """todo: docstring get_move_date_field. :returns: return datefield suitable move_in_date , move_out_date """ return forms.datefield(widget=extras.selectdatewidget(), initial=datetime.date.today()) class contactview(modelform): """todo: docstring contactview. :returns: contactview class in returning user information. """ birthday = forms.datefield(widget=extras.selectdatewidget(years=range(2025, 1939, -1))) move_in_date = get_move_date_field() move_out_date = get_move_date_field() message = forms.charfield(widget=forms.textarea) helper = formhelper() helper.form_tag = false helper.layout = layout( tabholder( tab( 'basic information', 'first_name', 'last_name', 'email', 'birthday', 'country', 'mobile' ), tab( 'moving , additional information', 'move_in_date', 'move_out_date', 'message', ) ) ) class meta: fields = ['first_name', 'last_name', 'email', 'mobile', 'birthday', 'move_in_date', 'move_out_date', 'country', 'message'] model = contactform widgets = { 'country': countryselectwidget()
}
admin.py:
from django.contrib import admin .models import contactform # register models here. class contactformadmin(admin.modeladmin): """docstring contactformadmin. """ class meta: model = contactform admin.site.register(contactform, contactformadmin)
i forgot register message inside `models.py'.
message = models.charfield(max_length=1000)
after makemigration
, migrate
had textarea
inside django admin
.
Comments
Post a Comment