django-forms

Inline formset returns empty list on save?

我们两清 提交于 2019-12-25 01:32:23
问题 When I try to save my inline formset it just returns an empty list and no changes are reflected in the database. I have tried doing it with no option and commit=False but they both have the same result. I know there is data because I printed the formset as a table, and I know it is valid because the property is_valid() method returns true. Here is the code: def edit(request): if request.method == 'POST': print(request.POST) form = TombstoneForm(request.POST) print(form.is_valid()) t = form

(Django, Satchmo) Developing products/cart line items with personalized fields/properties

一笑奈何 提交于 2019-12-25 01:08:56
问题 I'm looking into Python/Django to evaluate suitable e-commerce solution. For now Satchmo package seems to deliver solution to satfy most of my needs with Subscription product type. However, I still have home requirements to meet and I ended wondering that is Satchmo or some other cart/commerce package suitable for personalized products? I need the user to fill in some "personal details" regarding Subscription since Subscription products/orders can be assigned to other users and/or to non-user

Form redirect to URL containing query term? - pure HTML or Django

送分小仙女□ 提交于 2019-12-25 00:52:35
问题 I want to create a search box in Django that is situated at the URL /search, and redirects to a friendly URL like /search/queryterm - rather than having ?q=queryterm in the URL) So the user types in a query term, it takes them to /search/queryterm, and shows a list of results. I can get and display the results OK given a URL like /search/queryterm. But I don't know the best way to handle the URL redirect from the form. Should this be a redirect in pure HTML in the form (which feels slightly

Django How to pass object id via form action?

拥有回忆 提交于 2019-12-25 00:32:48
问题 I'm still having problems passing an object's id in the url of a form. adjust.html <form action="{% url 'classroom:deleteblock' classroom.id %}" method="post"> {% csrf_token %} {{ form }} <input type="submit" value="submit" /> </form> models.py class Classroom(models.Model): COURSE_NAME = ( ('MA8', 'Math 8'), ('SC10', 'Science 10'), ('PH11', 'Physics 11'), ('PH12', 'Physics 12'), ) BLOCK_NUMBER = ( ('11', 'Block 1-1'), ('12', 'Block 1-2'), ('13', 'Block 1-3'), ('14', 'Block 1-4'), ('21',

How to use exception handling in Django view

我只是一个虾纸丫 提交于 2019-12-25 00:28:14
问题 Suppose i have this code if form.is_valid(): form.save() Now suppose my form is valid i have exception that foregin key value is linked to more than one column so it will raise exception Now i want to know is there any way to grab that exception value and pass to jquery via AJAX Because form is valid so it comes inside the loop but its not able to go after form.save So how can i program that if exception occurs it get passed to jquery like if exception return HttpResponse(exception) I get

Form errors not displaying in UpdateView

[亡魂溺海] 提交于 2019-12-24 20:32:22
问题 I have an UpdateView that will display a form to either create the user profile or update the user profile. It works well, however, for some reason I can't get it to show the form errors. There should be form errors based on the ValidationErrors I have put in the model form. I suspect my views.py to be the cause of the form not displaying the errors. Here's my view: class ProfileSettings(UpdateView): model = Profile template_name = 'profile/settings.html' form_class = ProfileForm success_url

ModelChoiceField invalid literal for int() with base 10: ''

醉酒当歌 提交于 2019-12-24 20:29:31
问题 So I've spent the day trying to chase down a custom thing that I wanted to achieve using FormView. When I use FormView with HTML form method="POST", I am able to get the desired result, mostly. If a user clicks to submit a form and an empty field exists, they get an error message telling them the form is required. I'm aware that I can make the ModelChoiceField required on the form, but was trying to implement my own logic for this. I found through my searching that if I'm not updating

Contactform in footer of page

元气小坏坏 提交于 2019-12-24 20:05:04
问题 I have a contactform in the footer of a website. So it is on every page. It works, with one problem: as soon as it is sent, it doesn't show anymore. More specific I guess when my request is no longer empty. @register.inclusion_tag('home/tags/contact.html', takes_context=True) def contact_form(context): request = context['request'] if request.method == 'POST': form = ContactForm(request.POST) if form.is_valid(): subject = form.cleaned_data['naam'] from_email = form.cleaned_data['email']

Django form & rendering data from model

风流意气都作罢 提交于 2019-12-24 19:18:12
问题 I am currently struggling with Django forms. Based on the tickets model I generate this formset where users can choose the qty of tickets they want. After they will be redirected to the checkout page. My problem is, when I use {{ form.ticket }} I get a select field but that's not what I'm looking for. I just want to print out the tickets as seen in the screenshot below. Can anyone help me on that? How it should be: How it currently looks like: views.py from django.forms import formset_factory

django forms - how to update user data from previous comment when user posts a new comment

亡梦爱人 提交于 2019-12-24 18:23:26
问题 I feel like I'm really close, but not quite there yet. Please bear with me as I am very much so in the beginner stages of learning django. I have a feature where users can comment on each blog post. I want to display the total number of comments each user has next to his name. If that user has left 4 comments on 4 different posts, I want it to show "4 total comments" next to his name on each one of his individual comments throughout my website. I have made a model method that I put in my view