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?
Related
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 have a form in my app that has content attribute and uses tinymce like so:
from tinymce.models import HTMLField
class SomeModel(models.Model):
content = HTMLField('Content', null=True)
I also set up my tinymce in the installed apps and have the registered its url.
In my app it works fine and the user can edit and enter his\her content using tinymce. but when I register this model to the admin, all fields appear fine except the content which does not appear to have any way to input (and because its a required field, this means that I cant enter new items through the admin).
this looks like this in the admin:
how can I make tinymce also available in the admin screen?
bonus question: is there a safe way to use tinymce while letting the users use tinymce (currently im using form | safe which im guessing isn't really safe.
Create ModelForm
class BlogForm(ModelForm):
body = forms.CharField(widget=TinyMCE(attrs={'cols': 80, 'rows': 30}))
Admin.py
from models import Blog
from forms import BlogForm
class BlogAdmin(ModelAdmin):
form = BlogForm()
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)
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
I've made some changes to an admin form so that I could display a TextField like a CharField but the form itself looks pretty ugly in the admin menu as the form elements aren't stretching properly. I also don't want to display the name of model when I print it since it's already on the page. How would I make those changes? Ideally I would like the link field to take up all the remaining space shown the screenshot below.
admin.py
from linkrotator.models import Link, LinkList
from django.contrib import admin
from django import forms
class LinkModelForm( forms.ModelForm ):
link = forms.CharField( label = "Link")
class Meta:
model = Link
class LinkInline(admin.TabularInline):
form = LinkModelForm
model = Link
class LinkListAdmin(admin.ModelAdmin):
inlines = ( LinkInline, )
admin.site.register(LinkList, LinkListAdmin)
How it looks.
You need to edit the CSS for the admin section, easymode:
http://docs.djangoproject.com/en/dev/ref/contrib/admin/#modeladmin-media-definitions