Is it possible to resize textarea created by Django?
class TextAreaForm(forms.Form):
input_text_area = forms.CharField(widget=forms.Textarea)
I want to make it bigger but I don't know how. Is it possible to resize it using Django?
<br>
{{ text_area_form }}
<br>
I've found only solutions for resizing forms in Django administration.
The Django docs describe overriding default fields like so:
from django.forms import ModelForm, Textarea
from myapp.models import MyModel
class MyForm(ModelForm)
class Meta:
model = MyModel
widgets = {
'summary': Textarea(attrs={'rows':80, 'cols':20}),
}
This should be helpful to read through: (https://docs.djangoproject.com/en/dev/topics/forms/modelforms/#overriding-the-default-fields)
Related
I have integrated django-ckeditor in my blog, i have added placeholder with the help of widget in my forms.py like this
from blog.models import Contact
from ckeditor.widgets import CKEditorWidget
class ContactFrom(forms.ModelForm):
content = forms.CharField(widget=CKEditorWidget(attrs={'placeholder':"Type.."}))
class Meta:
model = Contact
fields = ("content",)
Even i can see placeholder in my textarea through inspect but not showing in my ckeditor what should i do?
I'm looking for a Django Model Field to render a HTML5 range slider like:
<input type="range" min="1" max="100" value="50">
This question comes close to Which Django Form Field can provide me a HTML output of <input type="range" />? but it asks for a form where I would search for an admin field for Django Admin.
Further this discussion shows as well how to use an IntegerField as range slider in forms:
https://code.djangoproject.com/ticket/20674
Long story short, can I use forms in Django Admin, or is there already a specific range field?
You can implement a widget, just like Django implements widgets. For example the NumberInput widget [GitHub] looks like:
class NumberInput(Input):
input_type = 'number'
template_name = 'django/forms/widgets/number.html'
We can do this ourselves, for example with a:
# app_name/widgets.py
from django.forms.widgets import NumberInput
class RangeInput(NumberInput):
input_type = 'range'
then you can use this widget with:
# app_name/forms.py
from app_name.widgets import RangeInput
class MyForm(forms.Form):
myint = forms.IntegerField(widget=RangeInput)
I have a problem.
Can I add image after the Model name in the django admin?
The postion I want to add the picture.
I want to see the books image when I login admin page
I have no idea about it
maybe I can use verbose_name with inject html tag?
Can django do it? Or I should use others way to do it?
Basically, You could customize ModelAdmin.list_display in Django admin list view, for example:
Suppose you have a model MyModel with an image field named image
from django.utils.html import format_html
#admin.register(MyModel)
class MyModelAdmin(admin.ModelAdmin):
list_display = ('id', 'image_tag')
def image_tag(self, obj):
return format_html("<img src="{}" width=200 height=80/>'.format(obj.image.url))
image_tag.short_description = 'Image'
I want to show select box options as raido buttons in Django Admin change model view. I don't want to write custom model forms. I'm looking for a way to render some select boxes as radio buttons while keeping auto generated model forms of the Django admin. I'm using django v 1.11.
Assuming my_field is the field, we want to be rendered as Radio Button
# admin.py
from django.contrib import admin
from django import forms
from .models import MyModel
class MyModelAdminForm(forms.ModelForm):
class Meta:
model = MyModel
exclude = ()
widgets = {'my_field': forms.RadioSelect}
class MyModelAdmin(admin.ModelAdmin):
form = MyModelAdminForm
admin.site.register(MyModel, MyModelAdmin)
I'm working in a form with a m2m field. I want that this field looks like the horizontal interface of the django admin site... ¿how i can do it?
thanks...
You need to use the FilteredSelectMultiple widget
from django.contrib.admin.widgets import FilteredSelectMultiple
from django import forms
from .models import Person
class PersonForm(forms.ModelForm):
some_field = forms.ModelMultipleChoiceField(Person.objects.all(), widget=FilteredSelectMultiple("Person", False, attrs={'rows':'2'}))
class Meta:
model = Person
You will also need to include the Javascript and CSS used in the admin. Here's an example