django-widget

JsonEditor integration with Django Admin

女生的网名这么多〃 提交于 2019-11-30 07:29:17
I am working on integrating JSONEditor into the Django admin. There is one field in my model that uses the Postgres JSON and the Tree editor in this library is perfect. models.py class Executable(models.Model): """ Simplified model for sake of the question.""" recipe = JSONField(null=True, blank=True) I've made decent progress (I think) integrating the JSONEditor library within the appropriate create/edit screen in the Django Admin. The data is displayed correctly upon loading but for some reason when I make edits within the JSONEditorWidget the changes are not saved. I'm sure there is some

Customize the styles of Django ClearableFileInput widget

和自甴很熟 提交于 2019-11-29 16:13:46
I have use ImageField in my django model to have the image upload facility. ImageField uses the ClearableFileInput widget but it does not provide well formatted html markup that i can customize using CSS. Shown bellow is the html markup that rendered by ClearableFileInput . <div class="form-group" id="div_id"> <label class="control-label " for="id_image"> Guide </label> <div class="controls "> Currently: <a href="/media/ide.png">de.png</a> <input type="checkbox" name="image_" id="image_"> <label for="image_te"> Clear </label><br> Change: <input type="file" name="image_te" id="id_i" class=

Django MultiWidget Phone Number Field

时光总嘲笑我的痴心妄想 提交于 2019-11-29 14:23:52
问题 I want to create a field for phone number input that has 2 text fields (size 3, 3, and 4 respectively) with the common "(" ")" "-" delimiters. Below is my code for the field and the widget, I'm getting the following error when trying to iterate the fields in my form during initial rendering (it happens when the for loop gets to my phone number field): Caught an exception while rendering: 'NoneType' object is unsubscriptable class PhoneNumberWidget(forms.MultiWidget): def __init__(self,attrs

Render only one part of a MultiWidget in Django

余生颓废 提交于 2019-11-29 12:08:05
I have a Django Form Field with a MultiWidget that consists of two TextInputs. When rendering the form in a template there is the handy notation {{ formname.fieldname }} for rendering a single field. When I use it for the field with the MultiWidget, it will display both HTML input elements. Is there a slight modification of the notation that will display only the first HTML input element? ( {{ formname.fieldname.0 }} does not work.) I found a solution to this problem that needs two pieces of code. First The render method that turns the MultiWidget into a string is relatively long. We need to

JsonEditor integration with Django Admin

◇◆丶佛笑我妖孽 提交于 2019-11-29 10:31:52
问题 I am working on integrating JSONEditor into the Django admin. There is one field in my model that uses the Postgres JSON and the Tree editor in this library is perfect. models.py class Executable(models.Model): """ Simplified model for sake of the question.""" recipe = JSONField(null=True, blank=True) I've made decent progress (I think) integrating the JSONEditor library within the appropriate create/edit screen in the Django Admin. The data is displayed correctly upon loading but for some

Grouping CheckboxSelectMultiple Options in Django

这一生的挚爱 提交于 2019-11-29 07:44:37
In my Django App I have the following model: class SuperCategory(models.Model): name = models.CharField(max_length=100,) slug = models.SlugField(unique=True,) class Category(models.Model): name = models.CharField(max_length=100,) slug = models.SlugField(unique=True,) super_category = models.ForeignKey(SuperCategory) What I'm trying to accomplish in Django's Admin Interface is the rendering of Category using widget CheckboxSelectMultiple but with Category somehow grouped by SuperCategory , like this: Category: Sports: <- Item of SuperCategory [ ] Soccer <- Item of Category [ ] Baseball <- Item

Customize the styles of Django ClearableFileInput widget

家住魔仙堡 提交于 2019-11-28 10:00:48
问题 I have use ImageField in my django model to have the image upload facility. ImageField uses the ClearableFileInput widget but it does not provide well formatted html markup that i can customize using CSS. Shown bellow is the html markup that rendered by ClearableFileInput . <div class="form-group" id="div_id"> <label class="control-label " for="id_image"> Guide </label> <div class="controls "> Currently: <a href="/media/ide.png">de.png</a> <input type="checkbox" name="image_" id="image_">

Render only one part of a MultiWidget in Django

血红的双手。 提交于 2019-11-28 06:01:57
问题 I have a Django Form Field with a MultiWidget that consists of two TextInputs. When rendering the form in a template there is the handy notation {{ formname.fieldname }} for rendering a single field. When I use it for the field with the MultiWidget, it will display both HTML input elements. Is there a slight modification of the notation that will display only the first HTML input element? ( {{ formname.fieldname.0 }} does not work.) 回答1: I found a solution to this problem that needs two

How do I use Django's MultiWidget?

女生的网名这么多〃 提交于 2019-11-28 02:52:48
The documentation is a bit lacking with respect to this feature. from django import forms class TwoInputWidget(forms.MultiWidget): """An example widget which concatenates two text inputs with a space""" def __init__(self, attrs=None): widgets = [forms.TextInput, forms.TextInput] I can see I need to create a "widgets" property with a list of other widgets, but after that it gets a little Sherlock Holmes. Would someone please explain to me how to use the MultiWidget widget? Interesting question and I think perhaps deserving of a little more attention in the docs. Here's an example from a

Filter ManyToMany box in Django Admin

冷暖自知 提交于 2019-11-28 02:48:29
I have a object with a many-to-many relation with another object. In the Django Admin this results in a very long list in a multiple select box. I'd like to filter the ManyToMany relation so I only fetch Categories that is available in the City that the Customer have selected. Is this possible? Will I have to create a widget for it? And if so - how do I copy the behavior from the standard ManyToMany field to it, since I would like the filter_horizontal function as well. These are my simplified models: class City(models.Model): name = models.CharField(max_length=200) class Category(models.Model