Questions tagged [django-multiwidget]

Pertains to Django's abstract class MultiWidget, and extensions thereof.

Pertains to the abstract Django class MultiWidget, and classes based off of it.

20 questions
51
votes
1 answer

How do I use Django's MultiWidget?

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): …
John Mee
  • 50,179
  • 34
  • 152
  • 186
16
votes
1 answer

Django subclassing multiwidget - reconstructing date on post using custom multiwidget

So my django book is back at university and I'm struggling to work this one out. I've subclassed django.forms.widgets.MultiWidget like so: class DateSelectorWidget(widgets.MultiWidget): def __init__(self, attrs=None, dt=None, mode=0): …
user257111
14
votes
1 answer

How to represent two model fields as one form field in Django?

I can't seem to figure out how to handle the following situation properly in Django: I have a date range in a model, which I store as two separate fields, date_start and date_end: start_date = models.DateTimeField() end_date =…
Herman Schaaf
  • 46,821
  • 21
  • 100
  • 139
5
votes
1 answer

how to work with modelform and multiwidget

Newbie to all this! i'm working on displaying phone field displayed as (xxx)xxx-xxxx on front end.below is my code. My question is 1. all fields are mandatory, for some reason,phone is not behaving as expected.Even if it is left blank its not…
stackover
  • 6,275
  • 6
  • 22
  • 20
4
votes
3 answers

Saving a form model with using MultiWidget and a MultiValueField

I'm trying to understand how to create forms by subclassing MultiWidgets and MultiValueFields. I have a simple Address model and associated forms: class Address(models.Model): user = models.ForeignKey(User) city =…
iva123
  • 3,395
  • 10
  • 47
  • 68
2
votes
1 answer

django multivaluefield & multiwidget - compress and/or decompress not working

All, I have a form with a MultiValueField that almost works. It uses a choicefield and charfield (with a corresponding Select and TextInput for the widgets):: custom_choices = [("one","one"),("two","two"),("other","other")] class…
trubliphone
  • 4,132
  • 3
  • 42
  • 66
1
vote
1 answer

Validate a MultiValueField with a custom MultiValueWidget in Django

I want to have a field and a widget that lets have an "approximated" date, the idea is have one and only one of the following : Exact date A year and maybe a month An initial and an end year Some compressed valid values could…
ikks
  • 131
  • 1
  • 5
1
vote
0 answers

Django Multiselect Filed showing List Index Out Of range Error in Window

I was working with Django and it's throwing an error IndexError: list assignment index out of range and the same code is working fine on Linux production, I used pip install django-multiselectfield for multiselect in Django, I am using this DATA=…
1
vote
2 answers

MultiValueField in an optional inline

I've set up a MultiValueField that's used in an inline. If I leave the MultiValueField blank, it appears to think that it's stilled filled in. As a result, I keep getting form validation errors because as far as the form is concerned those inlines…
Jordan Reiter
  • 20,467
  • 11
  • 95
  • 161
1
vote
0 answers

Multi-select in a Django Model with another Model's thumbnails as attributes

Is there a way to pass a Django model's Images as attributes to a Multi-select select field in another Django Model? If not, is there any way to display thumbnails of a model in another model's ModelForm as multiple select options?
1
vote
1 answer

Django MultiValueField

I'm struggling with some Django, where I want to make a custom MultiValueField combined with MultiWidget. I've read misc. tutorials, but it seem I'm missing something - most of them were quite old, which I suspect could be the reason. I'm using…
1
vote
1 answer

django multiwidget subclass not calling decompress()

I am trying to implement a MultiValueField for IP Adress/Domain Name entries. It works as expected for entering data. My Problem is that if I want to display the form bound to specific data, the IP Address/Domain Name field stays empty. All other…
Isaac
  • 810
  • 2
  • 13
  • 31
1
vote
1 answer

django multivaluefield & multiwidget - make one optional

This is related to an earlier question of mine. I want to have a MultiValueField which contains a Choice and TextInput widget. If the user selects "OTHER" from the Choice, then the value of the TextInput should be saved. Otherwise, the value of…
trubliphone
  • 4,132
  • 3
  • 42
  • 66
1
vote
4 answers

django - adding attributes to fields of a MultiValueField / MultiWidget

All, I have managed to get MultiValueField and MultiValueWidget working. But, apart from "choices", I cannot seem to add attributes (like "label" or "initial") to the sub-fields that make up the MultiValueField. Here is my (simplified) code: class…
trubliphone
  • 4,132
  • 3
  • 42
  • 66
0
votes
1 answer

How to split a form field to display multiple values in Django

My Journey model contains two fields, distance and time: class Journey(models.Model): distance = models.PositiveIntegerField(default=0) time = models.PositiveIntegerField(default=0) I am trying to create a Modelform where the time field…
sgt_pepper85
  • 421
  • 4
  • 14
1
2