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...
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?...
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...
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 ...
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:
...
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 ...
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...
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
...
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...
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...
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...
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...
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 ...
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?
...
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 ...
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 ...
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...
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(),
...
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...
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?
...