django-crispy-forms

Django form insert record instead of update record

孤人 提交于 2019-12-24 11:37:26
问题 I am having some issues trying to update some records in Django: When i try to update some record, the app insert a new one, I don't know why i have this behavior. Model class DetalleRecepcion(models.Model): id_proveedor = models.ForeignKey(Proveedor,db_column='id_proveedor',primary_key=True, verbose_name='Proveedor') anio = models.IntegerField( null=False) mes = models.IntegerField(verbose_name='Mes') fecha_recepcion = models.DateField(verbose_name='Fecha Recepcion') usuario = models

django-crispy-forms: form_class appears but label_class and field_class does not

☆樱花仙子☆ 提交于 2019-12-24 04:09:21
问题 This is my first time using crispy-forms and I am trying to make a horizontal crispy-form based on a ModelForm using bootstrap 3. In the output to the template "horizontal-form" shows up but "label_class" and "field_class". I've looked through many the documentation and stackoverflow, including this question and nothing seems to work. My Form: from django.forms import ModelForm from panews.models import Story from crispy_forms.helper import FormHelper from crispy_forms.layout import Layout

Django: Class based view can't render crispy form

耗尽温柔 提交于 2019-12-24 01:00:01
问题 Hi Stackoverflow people, I have trouble to render a crispy form with a class based view. Everything worked fine when I used the function based views. As usual I generate forms.py as follows: from django import forms from crispy_forms.helper import FormHelper from crispy_forms.layout import Layout, Div, Submit, HTML, Button, Row, Field from item.models import Item class CreateItemForm(forms.ModelForm): class Meta: model = Item exclude = ('user',) def __init__(self, *args, **kwargs): self

Change width for an input on Bootstrap3 horizontal forms

[亡魂溺海] 提交于 2019-12-23 21:00:44
问题 Reading django-crispy-forms I noticed than: The way you do horizontal forms in Bootstrap version 3 is setting some col-lg-X classes in labels and divs wrapping fields. This would mean a lot of hassle updating your layout objects for settings these classes, too much verbosity. Instead some FormHelper attributes have been added to help you easily achieve this. And an example is provided: helper.label_class = 'col-lg-2' helper.field_class = 'col-lg-8' My question is: How can I change default

How to use CreateView with crispy-forms in Django

梦想的初衷 提交于 2019-12-23 20:17:11
问题 I want to use CreateView along with crispy-forms generated layout. However, it seems that everything I pass to self.helper in forms.py is ignored. Form renders nicely, but only with fields generated by CreateView - all fields passed to Layout are missing. My views.py class MyView(CreateView): form_class = MyForm model = MyModel def form_valid(self, form): pass My forms.py: from django.forms import ModelForm, Textarea from crispy_forms.helper import FormHelper from crispy_forms.layout import

django-crispy-forms input size

无人久伴 提交于 2019-12-23 09:31:28
问题 According with django-crispy-form documentation, I will be able to change input width with class input-small . But my form always looks with width at 100%: Also, If I add css_class to Field the size remains at width:100% ( .form-control ) I have set form as documentation explains: class LoginForm(forms.Form): usuari = forms.CharField( help_text = u'Codi Usuari') paraula_de_pas = forms.CharField( help_text = u'Paraula de pas') # Uni-form helper = FormHelper() helper.form_class = 'form

Django Crispy Forms and Bootstrap Awesome Checkbox

老子叫甜甜 提交于 2019-12-22 12:23:48
问题 Is there any way to get Django Crispy-forms to emit the layout for a checkbox in a slightly different way to accomodate Bootstrap Awesome Checkbox (https://github.com/flatlogic/awesome-bootstrap-checkbox)? NOTE: this can't be done via a CSS change. The INPUT tag is no longer a child of the LABEL tag with the awesome-checkbox...it's a sibling at the same level as the LABEL tag. Crispy Forms renders like this: <div class="checkbox"> <label> <input type="checkbox"> Check me out </label> </div>

Django crispy-forms cannot find CSS

只愿长相守 提交于 2019-12-22 11:01:21
问题 I am using Django and Crispy Forms. I can get the form to render correctly, but no CSS formatting appears. What do I need to do? I have added CRISPY_TEMPLATE_PACK = 'bootstrap' to my settings.py file. The html file is as simple as it gets: {% extends 'base.html' %} {% load crispy_forms_tags %} {% block content %} {% crispy form %} {% endblock %} What else is necessary to make it work? I understand that since the bootstrap files come bundled with crispy_forms, I don't need to copy and

Django Crispy Forms - Add Button via Helper

落爺英雄遲暮 提交于 2019-12-22 10:04:06
问题 I studied the Crispy-Forms documentation and I tried to put an extra button into one of my forms. With self.helper.add_input(Button('back', "Back", css_class='btn')) I can add a nice button. But the Button() wont take an onclick or on_click-attribute. So how can I add logic to this button? Adding an onclick event with JQuery isnt a very nice solution... Thanks! Ron 回答1: This is not included by default (afaik..). If you just need this once, is possible to use crispy-forms HTML Layout Object

crispy-forms: add css class for one of the inputs

ⅰ亾dé卋堺 提交于 2019-12-21 07:34:43
问题 In my forms.py I have [...] self.helper.layout = Layout( Field('name'), Field('description'), ) self.helper.form_class = 'form-horizontal' self.helper.label_class = 'col-md-2 col-xs-3' self.helper.field_class = 'col-md-10 col-xs-9' [...] which renders to <div id="div_id_name" class="form-group"> <label class="control-label col-md-2 col-xs-3 requiredField" for="id_name"> Name </label <div class="controls col-md-10 col-xs-9"> <input id="id_name" class="textinput textInput form-control" type=