django-widgets

How do you change the default widget for all Django date fields in a ModelForm?

Given a set of typical models: # Application A from django.db import models class TypicalModelA(models.Model): the_date = models.DateField() # Application B from django.db import models class TypicalModelB(models.Model): another_date = models.DateField() ... How might one change the default widget for all DateFields to a cu...

Where does the widgets/foreign.html file reside in django trunk?

I would like to override (create custom) widgets/foreign.html template for a ForeignKey field but can't find this in the source. Browsing the Django SVN respository I can find these files at revision: 7966, but they are removed after this revision; http://code.djangoproject.com/browser/django/trunk/django/contrib/admin/templates/widget?...

In Django Admin, I want to change how foreign keys are displayed in a Many-Many Relationship admin widget

I have a ManyToMany relationship: class Book: title = models.CharField(...) isbn = models.CharField(...) def unicode(self): return self.title def ISBN(self): return self.isbn class Author: name = models.CharField(...) books = models.ManyToManyField(Book...) In the admin interface for Author I get a multiple sel...

Date format for django's SelectDateWidget

SelectDateWidget is very convenient but it normally seems to return dates in the format "%Y-%m-%d". It doesn't take a format parameter and doesn't have much documentation. Anyone run into this or have an idea how to work around it to get the output of the date into another format? There is this ticket, #6231 saying that there's a fix to ...

Django Widget Media doesn't work

Hi! I need a widget, which should only display a block, because i will add functionality with jQuery. I am trying to include the javascript and stylesheet trough the "Media" class of Widget and it doesn't work for me. Here is the code: class StarsWidget(Widget): """ Widget with stars for rating """ class Media: ...

Django MultiValueField - How to pass choices to ChoiceField?

I have a multivaluefield with a charfield and choicefield. I need to pass choices to the choicefield constructor, however when I try to pass it into my custom multivaluefield I get an error __init__() got an unexpected keyword argument 'choices'. I know the rest of the code works because when I remove the choices keyword argument from ...

Django MultiWidget Phone Number Field

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...

Custom Django admin widgets for many-to-many relations

Let's say I have the following Django models with these ForeignKey fields (simplified syntax): class Container(Model): items -> Item sub_items -> SubItem sub_sub_items -> SubSubItem class Item(Model): container -> Container children -> SubItem class SubItem(Model): container -> Container parent -> Item ...

django quantity form widget

Hello, I want to develop a basic quantity widget that is a dropdown selection box, consuming an integer which will be the maximum amount of quantity, users can select from 1 to the maximum quantity. And in the end my form will be using this widget and if somehow the given amount is greater than the maximum, it shouldn't validate. (indee...

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

Hi 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 sting up so that we...

Overwrite clean method in Django Custom Forms

Hi I have wrote a custom widget class AutoCompleteWidget(widgets.TextInput): """ widget to show an autocomplete box which returns a list on nodes available to be tagged """ def render(self, name, value, attrs=None): final_attrs = self.build_attrs(attrs, name=name) if not self.attrs.has_key('id'): final_attrs['id'] = 'id...

MultiWidget in MultiWidget how to compress the first one?

I have two MultiWidget one inside the other, but the problem is that the MultiWidget contained don't return compress, how do i do to get the right value from the first widget? In this case from SplitTimeWidget class SplitTimeWidget(forms.MultiWidget): """ Widget written to split widget into hours and minutes. """ def __i...

Django Forms - change the render multiple select widget

Hi, 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 javascript function which will ...

How to get a single widget to set 2 fields in Django?

Hi, I got a model with 2 fields: latitude and longitude. Right now they're 2 CharFields, but I want to make a custom widget to set it in admin - was thinking about displaying Google Maps, then getting the coordinates of the marker. But can I have 1 widget (a single map) to set 2 different fields? ...

Django: How do I add arbitrary html attributes to input fields on a form?

I have an input field that is rendered with a template like so: <div class="field"> {{ form.city }} </div> Which is rendered as: <div class="field"> <input id="id_city" type="text" name="city" maxlength="100" /> </div> Now suppose I want to add an autocomplete="off" attribute to the input element that is rendered, how would ...

Django: Country drop down list?

I have a form for address information. One of the fields is for the address country. Currently this is just a textbox. I would like a drop down list (of ISO 3166 countries) for this. I'm a django newbie so I haven't even used a Django Select widget yet. What is a good way to do this? Hard-code the choices in a file somewhere? Put ...

Django Custom Widget For ManyToMany field

Does anyone know of a widget that displays 2 select boxes. One shows a list of all object in a model and the other shows the objects which have been selected. The user can then select an object from the first list, click an >> button which moves it to the 'selected' list. Then when the form is saved the objects in the selected list ar...

How to change ManyToManyField widget to CheckboxSelectMultiple without overriding field definition in a ModelForm

Hi, I have django ModelForm for model with ManyToManyField. I want to change widget for this field toCheckboxSelectMultiple. Can I do this without overriding a field in a form definition? I constantly use code similar to this: class MyModel(ModelForm): m2m_field = forms.ModelMultipleChoiceField(queryset = SomeModel.objects.all(), ...

Django: How to check if there are field errors from within custom widget definition?

I'd like to create widgets that add specific classes to element markup when the associated field has errors. I'm having a hard time finding information on how to check whether a field has errors associated with it, from within widget definition code. At the moment I have the following stub widget code (the final widget will use more co...

Widget filling values in two fields

I know that if I need a custom "selector" for a field in django-admin I need to create a custom widget. But what if the widget have to produce two values, for example X and Y coordinates, how can I fill them in two different fields from the model? ...