Questions tagged [django-widget]

1

votes
1

answer
303

Views

how to add markers and center map in signup form django-map-widget

Using django-map-widget to render a map widget in forms. it works fine, but... I want to trigger the map in two ways (dynamically via javascript): trigger to re-center map on x,y trigger to add a marker to map on x,y I tried so many ways, but i can't solve it. You can see and play with my form here...
Michael Lind
1

votes
0

answer
39

Views

Django doesn't respect the maxlength widget attribute

I have the following field in model: short_description = models.CharField(max_length=205) and the widget in ModelForm: 'short_description': forms.Textarea(attrs={'rows': '3', 'minlength': 250,'maxlength': 250}) The issue: In HTML, input, Django adds correctly minlength value, but for the maxlength...
user3541631
1

votes
0

answer
111

Views

django-widget-tweaks with django custom tags

I am using django-widget-tweaks to render my django form fields. Now I need to show the return value of a custom django tag as the value of my render field. This is my template tag from forex_python.bitcoin import BtcConverter @register.simple_tag def btc_price_in_sgd(): coin_obj = BtcConverter() pr...
sarathkumar P M
1

votes
0

answer
162

Views

Add Font Awesome icon with label_tag

How do I add a Font Awesome icon like to the following {{form.date.label_tag}} which uses widget_tweaks? I know generally you'd just do it like this Add but I haven't had any luck. It just outputs the 'Date added:'
Reez0
1

votes
1

answer
125

Views

Replacement for django `render_options`

So I am implementing this answer: Country/State/City dropdown menus inside the Django admin inline, but the def render piece of code needs to be redone.... I have managed to redo it, but I am struggling to find a replacement (or the correct code) for the self.render_options method (which was depreca...
Walucas
1

votes
0

answer
39

Views

Default specific option checked in ParentalManyToManyField wagtail, using django-form

I am working with a multi-site wagtail project. And I want an event class which contains ParentalManyToManyField field called sites. The idea is that each event will be associated with multiple sites not necessarily all. Two sites X and Y have lots of events and most of them are common. So I want t...
Bikash kharel
0

votes
0

answer
3

Views

Django model-forms widget choice based on URL variables

lets say I have a form based on the model: Form1: class Meta: model = Comment widgets = {'field1': forms.HiddenInput } # option 1 #or widgets = {'field2': forms.HiddenInput } # option 2 And I have 2 widgets options . First -displays 2nd field but hides 1st and second -other way around. Choice of...
1

votes
0

answer
47

Views

Django form widget : submit onchange

I have a Django form with django-select2 and I would like to submit this one, not with a submit button but with onchange widget attribute. I tried to write this : class ManageDocForm(forms.Form): def __init__(self, *args, **kwargs): super(ManageDocForm, self).__init__(*args, **kwargs) app_list = for...
Essex
1

votes
1

answer
28

Views

Django Map Widgets drawing polygons

I'm just wondering, what is the name of the polygon field in the django-map-widgets module for GeoDjango and whether it supports drawing polygons?
kiwis
1

votes
1

answer
3.2k

Views

Django Forms - change the render multiple select widget

In my model I have a manytomany field mentors = models.ManyToManyField(MentorArea, verbose_name='Areas', blank=True) In my form I want to render this as: drop down box with list of all MentorArea objects which has not been associated with the object. Next to that an add button which will call a ja...
John
1

votes
1

answer
2.5k

Views

Filter many-to-many multiple select field

I have a object (Book) with a many-to-many relation with another object (Category). 'Category' is used to render subcategories too. The diference between a category and a subcategory is that a category has 'category_parent=None', while a subcategory has a category as a parent. --models.py-- class C...
user553417
1

votes
2

answer
2k

Views

Custom Django CheckboxSelectMultiple widget rendered as an empty list

I am trying to create a CheckboxSelectMultiple widget that lists all the content types of my project. I started by using the base widget when defining a MultipleChoiceField field in a ModelForm and it worked fine. I would like now to make it a custom widget I can import though an app into any projec...
Dr Tuple
1

votes
1

answer
412

Views

Django Contrib Comments: How to override the comment's textarea widget?

Using django.contrib.comments, I've defined a custom comment app. I wanted to override the text area widget so that the textbox appears smaller. So what I created was this: #forms.py class CustomCommentForm(CommentForm): #...otherstuff... comment = forms.CharField(label=_('Comment'), widget=forms.Te...
powlo
1

votes
1

answer
7.1k

Views

How to work with time picker widget in Django template?

I am working on a Django based Application, and i stuck in some place where i want to save a time given by the user and the no of days (Monday-Sunday) in my database. user will choose a time from Time picker widget or any other way, but it return into the 07 : 30 format. User will also choose day'...
Amit Pal
1

votes
1

answer
763

Views

how to delete the -— generated by select choices

i have a question on how do i get rid of the ---- from the select drop down menu not to show the null(---) in the first row. I found from stackoverflow on RadioSelect and i manage to get rid of the --- but i am stuck in the select drop down menu...:( here is my coding example. models.py colorradio...
noobes
1

votes
1

answer
459

Views

How can I extend a django admin widget so it's still optional?

I've been scouring the internet for a couple days and couldn't find anything, so I'm hoping you guys can point me in the right direction. I'm trying to customize the django admin so that a button appears inline after a URL field. The button appears, and the javascript works, except despite marking i...
leo
1

votes
2

answer
1.3k

Views

How do I access the id of a Django Widget from the widget definition?

I am creating a custom widget for a datetime field: class MySplitDateTimeWidget(forms.SplitDateTimeWidget): def format_output(self, rendered_widgets): mytimeid = self.widgets[1].attrs['id'] #####NEED HELP HERE temp = 'javascript:$('%s').val(new Date().getHours());' % mytimeid temp1 = 'Now' % temp r...
rsp
1

votes
1

answer
327

Views

Cant get Custom widget to work by replacing django's default date time widget in django admin

I had asked a question here but I think its dead. I even updated it with my progress. So after that I worked a little more with firebug for firefox and discovered some errors that make no sense to me. But before that heres my code: (My app name is ui) ui/admin.py class MyModelAdmin(admin.ModelAdmin)...
1

votes
2

answer
440

Views

Django FilteredSelectMultiple with a massive amount of data

I have the following models: class Student(models.Model): class Meta: app_label = 'ground' name = models.CharField(max_length=255) def __unicode__(self): return unicode(self.name) class Program(models.Model): class Meta: app_label = 'ground' name = models.CharField(max_length=255) student = models.M...
nelsonvarela
1

votes
1

answer
405

Views

Add CSS class to entire form in Django

Suppose I have a form: class MyForm(forms.Form): ... and then in a view I construct it: ... form = MyForm() ... I would like to add a CSS class to the entire form, so that I can render it as something like this: {% csrf_token %} {{ form }} What is the proper way to achieve that (other than define a...
jazzblue
1

votes
1

answer
714

Views

Django Iterating Over CheckboxSelectMultiple Renders Numbers

I'm trying to iterate over a MultipleSelect form that utilizes a CheckboxSelectMultiple widget and display each checkbox within. Here is the code for the iteration: {% for choice in form.mp4_rasters %} {{ choice }} {% endfor %} Here is the Form I declared: from django import forms MP4_CHOICES = ('24...
coltonoscopy
1

votes
1

answer
52

Views

Can I change a form widget class without redefining it explicitly in Django?

I'm trying to change the class of a Django form field. My form looks like: class MyForm(forms.Form): my_field = forms.ChoiceField(choices=myChoices) Why is it that it only works to change the class of the Select field explicitly? I want the default Select widget, is there a way to change its attrs w...
YPCrumble
1

votes
1

answer
295

Views

How to pass parameters to widget js asset?

It is possible to pass custom js to a widget, as explained in the documentation. In my case, the custom js is this: function setUpImagePreview(inputId, imgId) { ... } window.onload = function() { // IDs hardcoded, VERY BAD! How to solve this? setUpImagePreview('id_brand_logo', id_brand_logo_img'); }...
dangonfast
1

votes
1

answer
365

Views

Django form field widget becomes hidden

Model field links as foreign_key to another model which has big amount of entries. I decided to replace default select for foreign_keys with simple link. And it works grate besides the fact that field becomes hidden! What should I do to avoid that? admin.py class SeriesAdmin(ModelLinkAdminFields, ad...
Alex T
1

votes
1

answer
589

Views

Using stylesheets with django-widget-tweaks?

I'm struggling to understand how to use Django-Widget-Tweaks with a stylesheet. For example, here's my basic form with bunch of CSS classes pulled from my stylesheet - obviously not yet wired up with Django. Email How should this be used with Django-Widget-Tweaks? I'm presuming it's something like t...
user6361549
1

votes
2

answer
467

Views

Using jQuery datepicker with multiple django forms in one page

So I have a create announcement form and then an edit form for each announcement and each form has its own datepicker. My function for controlling the datepicker is: $(function() { $( '.datepicker' ).datepicker({ changeMonth: true, changeYear: true, }); }); Initially my issue was that using the dat...
Catherine
1

votes
3

answer
912

Views

How to change datetime format in Django-filter form?

I'm creating a filter which contains datetime range choice. I would like user to be able to input date in this format: 24.08.2017 17:09 From docs, it is possible to specify a widget (from django.forms) and widget has attribute input_formats. So this would be a solution: datetime_range = django_filt...
Milano
1

votes
1

answer
423

Views

How change html template of ImageField in edit form?

I use Django 1.11 in my project. In my edit form I have ImageField. Django by default render html which you can see below. How change html of ImageField in edit form correctly? I tried next code but Django raise error TemplateDoesNotExist. Django dont see template_file in my custom widget? How to fi...
Nurzhan Nogerbek
1

votes
1

answer
925

Views

template tag 'add' requires 2 arguments, 1 provided

I have used add before but getting this strange error this time: django.template.exceptions.TemplateSyntaxError: add requires 2 arguments, 1 provided with the following code: {% render_field form.full_name type='hidden' class='form-control' \ value=user.first_name|add:'something' %} However I don't...
Anupam
0

votes
1

answer
0

Views

Django textarea widget does not have attribute “input_type”

I'm trying to check input type of widget as below: for field in form: if field.field.widget.input_type == 'checkbox': do_smth() else: do_smth_else() but it seems Django Textarea widget does not have attribute 'input_type'. I already solved the problem by wrapping input_type check in try/except block...
renkse
1

votes
1

answer
0

Views

In django forms custom widget return list as value instead of string

I am writting a custom widget which I want to return a list as the value. From what I can find to set the value that is returned you create a custom value_from_datadict function. I have done this def value_from_datadict(self, data, files, name): value = data.get(name, None) if value: # split the...
John
1

votes
1

answer
0

Views

How to set MaxDate and MinDate of a SelectDateWidget in Django?

How to set MaxDate and MinDate of a SelectDateWidget in Django? I am using that widget for a birthdate field. #found in: from django.forms.extras.widgets import SelectDateWidget from django import forms def someform(forms.Form): birthdate = forms.DateField(widget=SelectDateWidget()) So how do I chan...
Joseph Lafuente
1

votes
1

answer
1.9k

Views

Django 1.4 Want to make birthdate field utilizing SelectDateWidget not required on my form

I am trying to create a form for the user to change their profile account information on their own. Currently I have it so they can update their first, last and username, gender and 'birthdate'. The 'birthdate' is the only one I can't get to be not required. Currently my form checks if no input was...
NightCodeGT
1

votes
1

answer
1.3k

Views

Accessing ModelChoiceField queryset from custom widget

I have a form that has a ModelChoiceField. I have created a custom widget for dealing with ModelChoiceFields, the widget extends forms.TextInput, so: class SelectWidget(forms.TextInput): def __init__(self, attrs): super(SelectWidget, self).__init__(attrs) def render(self, name, value, attrs=None): v...
PT114
1

votes
1

answer
1.2k

Views

How to use django admin many to many field selector widget

I want to use this How can I use it for my many to many modelform. Basically I want the add button, which allows me to add the many to many objects.
Akash Deshpande
1

votes
2

answer
2.1k

Views

Django: How to get the selected value from a custom widget?

I'm writing a custom Form widget that overrides the choice method in django.forms.models.ModelChoiceIterator: class CustomIterator(ModelChoiceIterator):...
3cheesewheel
1

votes
1

answer
218

Views

Django disable widget caching?

So I have a form where I defined a select widget like this: class AdHocVoucherTemplateForm(ModelForm): class Meta: model = AdHocVoucherTemplate widgets = { 'retailer_id': Select(choices=[(r.pk, r.name) for r in Retailer.objects.all()]), } This way I achieve a select input field with all retailers. U...
Richard Knop
1

votes
1

answer
630

Views

create a selector widget in django form

I want to create a form widget like the permission selector in the admin page. The model where i want to choose the records is a view from the database class Ftp_Archivo(models.Model): id_lista = models.IntegerField(primary_key=True) id_proveedor = models.IntegerField() codigo_asignado = models.Char...
joselegit
0

votes
0

answer
3

Views

django-widget-tweaks error while rendering in Django 2.1

While trying to use OSMField from django-osm-field and rending it with with django-widget-tweaks I am getting this error: File '/usr/local/lib/python3.7/site-packages/django/forms/boundfield.py', line 93, in as_widget renderer=self.form.renderer, TypeError: render() got an unexpected keyword argumen...
ketimaBU
1

votes
1

answer
810

Views

Django formset not rendering with django-widget-tweaks

I am getting the error 'LoginForm' object has no attribute 'as_widget' whenever I use formset. I really do not know what is the problem as the forms renders properly with normal Django forms. I am trying to see what characteristics in the formset is giving this problem with django-widget-tweaks, but...
Jam1

View additional questions