django-widget

Is there a 'SelectDateTime' widget for django forms?

十年热恋 提交于 2019-12-08 11:54:32
问题 Basically the same as the SelectDate Widget but with an hour component as well. Can't seem to find one in the official docs? 回答1: Here's the split date/time widget I use: First, the Time widget. There's a LOT of code. I'm copy/pasting here, so there may be imports you don't need. I keep this in a file called "custom_form_widgets.py". At the bottom, you'll see my "FriendlySplitDateTimeWidget" class, which you can use in your forms. The hours can be based on a 24 or 12 hour clock. The date

django radioselect render to table

早过忘川 提交于 2019-12-06 09:29:06
问题 I want to render the django form widget radioselect into a table rather than a ul list. With labels in the first row and the radio buttons below in the second row. One cell for each button. e.g. ------------------------------- | label 1 | label 2 | label 3 | ------------------------------- | O | O | O | ------------------------------- I've looked at the default selectradio widget but the render function seems so complicated, calling many different classes to do each part of the render. Does

django admin how to display widget on readonly field

无人久伴 提交于 2019-12-05 21:34:23
问题 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

Django Widget Media doesn't work

旧时模样 提交于 2019-12-05 21:32:21
问题 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: js = ( settings.MEDIA_URL + 'js/rating.js', ) css = { 'screen': ( settings.MEDIA_URL + 'css/rating.css', ) } def render(self, name, value, attrs=None): if value is None: value = '' attrs =

Django MultiValueField - How to pass choices to ChoiceField?

落花浮王杯 提交于 2019-12-05 21:24:21
问题 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):

Django admin GenericForeignKey widget

≡放荡痞女 提交于 2019-12-05 08:54:44
I'm creating a Django app where all the models can be related to each other in an order set by the user. I'm setting all this up using GenericForeignKeys. The kicker is that I need to be able to support multiple collections of these types of relationship/admin. So one object can have a more than one collection of related objects. Does anyone know of a good GenericForeignKey widget for this situation? Preferably, it would be an autocomplete search that populates the admin form since I can end up having a large number of objects. Here is the code for my app to get a better idea of what I mean.

Django SelectDateWidget to show month and year only

試著忘記壹切 提交于 2019-12-04 22:44:55
问题 Is there a different widget or argument that will allow django to only show/take the year and month input instead of year, month and day? Currently using SelectDateWidget. 回答1: There's a snippet here, which sets the day to 1 (presuming you've got a DateField that this value will end up in, you'll need to get some kind of day). The code is like this (just in case Django snippets disappears): import datetime import re from django.forms.widgets import Widget, Select from django.utils.dates

django radioselect render to table

会有一股神秘感。 提交于 2019-12-04 17:28:45
I want to render the django form widget radioselect into a table rather than a ul list. With labels in the first row and the radio buttons below in the second row. One cell for each button. e.g. ------------------------------- | label 1 | label 2 | label 3 | ------------------------------- | O | O | O | ------------------------------- I've looked at the default selectradio widget but the render function seems so complicated, calling many different classes to do each part of the render. Does anyone have any examples of how to do this or could provide a simple solution? You need to subclass

Django: Admin: changing the widget of the field in Admin

本秂侑毒 提交于 2019-12-04 15:35:02
问题 I have a model with a boolean value like that: class TagCat(models.Model): by_admin = models.BooleanField(default=True) This appears as a checkbox in admin. How could I use this as a radio button in admin? Also, how do I make it be always with a certain selected value in admin? Also, I want the default value to be the opposite, when a non-admin user adds a TagCat . This field should be hidden from him. Can someone tell me how to do this? Django documentation doesn't seem to go in such details

Date format for django's SelectDateWidget

泄露秘密 提交于 2019-12-04 13:09:57
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 have it use a DATE_FORMAT setting from settings.py (though I don't see why it can't just be given a format parameter also). There's a patch in the ticket from 2 months ago to implement this, so it seems I would have to get the latest dev version of django to