I'm trying to add django-faicon field in a form inside my template.
I have a form like:
from faicon.fields import FAIconField
class SomeForm(forms.Form):
icon = FAIconField()
And I add the field into template:
{{ form.icon }}
But instead a real icon field I see on webpage:
<faicon.fields.FAIconField>
What is a proper way to render icon field outside Django admin?
Related
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 am using django_fiter package for filter data, but it's displaying filter in the input box or some filter in the dropdowns, but I want all filters in the checkbox (like as Django default admin panel filter), please let me know how I can convert it in checkbox filter on my website front panel.
Here is my code for filter view form...
<form method="get">
{{ filter.form|bootstrap }}
<input type="submit" />
</form>
and here is my views.py file code...
class ProductFilter(django_filters.FilterSet):
name = django_filters.CharFilter(lookup_expr='icontains')
class Meta:
model = Product
fields = ['saleprice', 'title','veg_non','brand','supplement']
it's looking like this...
and I want in this format, please let me know how I can customize it.
I have a model form field which is a choice field. Instead of having the default widget:
I would like to have a grid of cards like so:
With each of the choices that would have been in the default widget in a card.
How do I edit the python form to achieve this?
Here is my form:
from django import forms
from . import models
class PostJobForm(forms.ModelForm):
class Meta:
model = models.Job
fields = [
'title',
'description',
'pay',
'category'
]
You will have to move away from default django forms and create the forms using html, css and js the way you want.
When using django forms, it uses default templates.
<form method="post" action"">
<input type="text" id="id_title" name="title">
<!--this input is for title field of your model form-->
</form>
as shown above you can do it for any field that you want
IMP keep the name attribute of input and that of model field same
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)
how to access rich text field as a variable in django template language using in mezzanine CMS
If you are using the RichTextPage model built into Mezzanine, the tag is:
{{ page.richtextpage.content }}
If you have a custom model called CustomModel descended from Page that has a field called content that uses Mezzanine's RichTextField, the tag is:
{{ page.custommodel.content }}