0👍
✅
Turns out to have been a false alarm. My designer radically changed the css in a way that breaks crispy forms. I thought I had isolated the changes, but once I removed all the application generated CSS all worked well. Sorry for the false alarm.
0👍
There may be few errors:
EntryForm
has linemodel = Entry
, instead must bemodel = Payment
, as in model you describePayment
- In
EntryForm.__init__
lack of linesuper(EntryForm, self).__init__(*args, **kwargs)
-
your
__init__
declaration contain redundant(?) parameterrequest
so declaration must bedef __init__(self, *args, **kwargs): #without request
Please try this changes.
Your code(in my edition, below) works ok with normal behaviour of radio buttons, it normally creates new payment and prints existing.
models.py without changes
forms.py
from crispy_forms.helper import FormHelper
from crispy_forms.layout import Layout, Field, Fieldset, ButtonHolder, Submit
from crispy_forms.bootstrap import InlineRadios
class EntryForm(forms.ModelForm):
class Meta:
model = Payment # !not Entry
fields = [
'title', 'production_type'
]
def __init__(self, *args, **kwargs): #!without request
super(EntryForm, self).__init__(*args, **kwargs) #this line present
self.helper = FormHelper()
self.helper.layout = Layout(
'title',
InlineRadios('production_type'),
Submit('submit', 'Submit'), # i miss your submit button, so adding here
)
views.py
from django.views.generic.edit import CreateView
# it creates new payment
class PaymentCreate(CreateView):
model = Payment
form_class= EntryForm
template_name='payment_form.html'
success_url = '/payment/'
# this usual view just print form with already created instance
def PaymentView (request):
form = EntryForm(instance = Payment.objects.get(id=4))
c = {'form': form}
return render(request,'payment_form.html', c)
payment_form.html
{% load crispy_forms_tags %}
<html>
<head>
</head>
<body>
{% csrf_token %}
{% crispy form %}
</body>
</html>
urls.py:
...
#i made 2 views, one for 'usual' view, one for generic view
url(r'payment_view/', PaymentView),
url(r'payment/', PaymentCreate.as_view()),
...
- [Django]-Dynamic SEO-friendly URLs
- [Django]-Collectstatic command not run when deploying to Heroku, but setup is perfectly fine
- [Django]-Why does MySQL treat Japanese alphabets hiragana and katakana the same, and how can you make it compatible with Django?
- [Django]-Django.core.urlresolvers.resolve incorrect behavior under apache non-root deployment
- [Django]-How to download data from azure-storage using get_blob_to_stream
Source:stackexchange.com