django-widget

django admin how to display widget on readonly field

大憨熊 提交于 2019-12-04 04:28:02
I want to display my widget on the field at django admin when the field is readonly. admin.py class AudioTrackAdminInline(admin.StackedInline): model = AudioTrack form = AudioTrackForm readonly_fields = ('file',) forms.py class AudioTrackForm(forms.ModelForm): class Meta: model = AudioTrack widgets = { 'file': MediaFileInput, } # my widget When the file is not readonly, it displays widget OK. But when i include it as readonly, i see text line. (Django does not to use my form if readonly) How can i get it to use form even at readonly field? or How to display another widget if i set my field

Django MultiValueField - How to pass choices to ChoiceField?

南笙酒味 提交于 2019-12-04 02:48:04
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 __init__ and super, the multivaluefield displays correctly but without any choices. This is how I setup my custom multivaluefield: class InputAndChoice(object): def __init__(self, text_val='', choice_val=''): self.text_val=text_val self.choice_val=choice_val

Django Custom Widget For ManyToMany field

自作多情 提交于 2019-12-03 21:06:26
问题 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 are saved in the manytomany field. Thanks 回答1: django.contrib.admin.widgets.FilteredSelectMultiple 来源: https://stackoverflow.com/questions/3006401/django-custom

How to use jQuery UI Datepicker as a Django Widget?

徘徊边缘 提交于 2019-12-03 16:32:10
问题 Some of my Django 1.3 models have DateField properties. When a form is generated, I'd like to use the jQuery UI Datepicker instead of a plain text field. I understand that I could create new widgets but I don't understand how. In addition, I am not sure if anything like this has already been done for Django (I googled it, no chance). How to create a Django Widget that I can reuse across multiple models (and page) for the jQuery UI Datepicker? 回答1: JQueryUI has a very good date UI picker. You

Django: Country drop down list?

怎甘沉沦 提交于 2019-12-03 06:57:38
问题 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 them in the database? In the template? 回答1: Check out "choices" parameter of a CharField. You might also want to take a look at django-countries. 回答2: Django

How to use jQuery UI Datepicker as a Django Widget?

亡梦爱人 提交于 2019-12-03 05:37:57
Some of my Django 1.3 models have DateField properties. When a form is generated, I'd like to use the jQuery UI Datepicker instead of a plain text field. I understand that I could create new widgets but I don't understand how. In addition, I am not sure if anything like this has already been done for Django (I googled it, no chance). How to create a Django Widget that I can reuse across multiple models (and page) for the jQuery UI Datepicker? Dave JQueryUI has a very good date UI picker. You can get it here: http://jqueryui.com Say for example you have the following form: class DateForm(forms

Django: Country drop down list?

邮差的信 提交于 2019-12-02 21:38:39
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 them in the database? In the template? Check out " choices " parameter of a CharField. You might also want to take a look at django-countries . Django Countries from django_countries.fields import CountryField class Foo(models.Model): country = CountryField() Ended up

Django Custom Widget For ManyToMany field

好久不见. 提交于 2019-11-30 22:53:03
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 are saved in the manytomany field. Thanks django.contrib.admin.widgets.FilteredSelectMultiple 来源: https://stackoverflow.com/questions/3006401/django-custom-widget-for-manytomany-field

Django - Show BooleanField in a formset as one group of radio buttons

白昼怎懂夜的黑 提交于 2019-11-30 20:48:08
I have the following models: class Profile(models.Model): verified = models.BooleanField(default=False) def primary_phone(self): return self.phone_set.get(primary=True) class Phone(models.Model): profile = models.ForeignKey(Profile) type = models.CharField(choices=PHONE_TYPES, max_length=16) number = models.CharField(max_length=32) primary = models.BooleanField(default=False) def save(self, force_insert=False, force_update=False, using=None): if self.primary: # clear the primary attribute of other phones of the related profile self.profile.phone_set.update(primary=False) self.save(force_insert

Django MultiWidget Phone Number Field

孤街浪徒 提交于 2019-11-30 09:25:51
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=None): wigs = (forms.TextInput(attrs={'size':'3','maxlength':'3'}),\ forms.TextInput(attrs={'size':'3',