django-forms

How can I return a queryset for a fk or m2m field in wagtail admin create form?

醉酒当歌 提交于 2020-03-26 03:06:05
问题 My question holds for any wagtail panel that returns select options from a foreignkey or M2M relationship, like a PageChooserPanel or SnippetChooserPanel. How can I filter the list of options server-side, for the user to only see the information he has access to? I have a Plan model. When creating a new plan, I would like request.user to only see the list of companies he is affiliated to. from modelcluster.models import ClusterableModel from wagtailautocomplete.edit_handlers import

Django datetimefield not showing datetimepicker widget for new inline form rows

≡放荡痞女 提交于 2020-03-25 17:58:12
问题 In regards to the image below, when I click "add entry", the new entry row no longer has the datetimepicker widget. Which is odd because it has the right class. The +1 field represents the django form auto-added additional field. Which seems to work fine. It's only the fields that are added after the page has rendered which may be a key to the solution. I am using the flatpickr package as my datetimepicker widget. trade_form.html {% extends 'dashboard/base.html' %} {% load static %} {% block

Django: form validation errors on form creation

余生长醉 提交于 2020-03-24 00:19:06
问题 Let's say I have a Django form with ChoiceField: class MyForm(forms.Form): name = forms.CharField(label="Name", required=True) some_object = forms.ChoiceField(label="Object", choices=[(0, '-----')] + [(x.id, x.name) for x in Obj.objects.all()]) Choisefield is being initialized with list of objects headed by 'empty choice'. There is no object with pk=0. In that form I have a clean() method: def clean(self): if not Obj.objects.filter(self.cleaned.data['some_object'].exists(): self.errors.update

Django: form validation errors on form creation

こ雲淡風輕ζ 提交于 2020-03-24 00:17:17
问题 Let's say I have a Django form with ChoiceField: class MyForm(forms.Form): name = forms.CharField(label="Name", required=True) some_object = forms.ChoiceField(label="Object", choices=[(0, '-----')] + [(x.id, x.name) for x in Obj.objects.all()]) Choisefield is being initialized with list of objects headed by 'empty choice'. There is no object with pk=0. In that form I have a clean() method: def clean(self): if not Obj.objects.filter(self.cleaned.data['some_object'].exists(): self.errors.update

Django cannot create or render comments

ε祈祈猫儿з 提交于 2020-03-24 00:16:46
问题 Hi have this structure to handle users posts and comments my post model is from django.db import models from django.contrib.auth.models import User class Post(models.Model): user = models.ForeignKey(User, on_delete=models.CASCADE, default=0) profile = models.ForeignKey('users.Profiles', on_delete=models.CASCADE, null=True, default=1, blank=True) title = models.CharField(max_length=100, blank=True, null=True) desc = models.CharField(max_length=1000, blank=True, null=True) photo = models

How to dynamically delete object using django formset

泄露秘密 提交于 2020-03-21 06:41:52
问题 Django says, i should render inline formset this way: {{ formset.management_form }} {% for form in formset %} {{ form.id }} {{ form.field_1 }} {{ form.field_2 }} <button type="button"> delete </button> {% endfor %} <button type="submit"> submit </button> Ok. But what if i want to delete some formset objects ( form ) dynamically? User press delete button - i remove form from the DOM, i use ajax to remove object, related to the form from the DATABASE. It works ok till this point. But when user

Render ChoiceField options in Django template

寵の児 提交于 2020-03-17 11:02:21
问题 Given a ChoiceField in Django fruits = ChoiceField(label="Fruits", choices=(('A', 'Apple'), ('B', 'Banana'), ('C', 'Cherry') ) How do I display the form options in Django Templates in 1.9? For example, I tried the following but cannot display the form data: <table class="table table-bordered table-condensed"> <tr> <th> <label for="{{form.fruits.id_label}}"> {{form.fruits.label}} </label> </th> <td>{% for value, displayable in form.fruits.choices %} <option value="{{value}}">{{displayable}}<

Django DateTimeInput Type 'datetime-local' Not Saving To Database

∥☆過路亽.° 提交于 2020-03-05 04:23:27
问题 I'm working on a django app to document trades. All the trade documentation is done on one page with an inline formset that shows all the entries and exits for a trade. All work well up to the datetimeinput field. If I remove the 'type' the form works great but is very non-user friendly. Working entries with no 'type' Non-working entries with 'type': 'datetime-local' So I guess you could say there are several issues datetime-local creates, or maybe it's not datetime-local to blame. I've been

unable to save data using django formsets

删除回忆录丶 提交于 2020-03-04 20:51:01
问题 The data entered in the form is not saving in the database and it is not showing any errors. Iam trying to create an exam with atleast one question, using ExamModelForm and QuestionFormset. After entering exam details and questions in create_exam_with_questions.html, the create button is not saving the data into the database views.py from django.shortcuts import render from django.shortcuts import redirect from django.http import HttpResponseRedirect, HttpResponse from .forms import

unable to save data using django formsets

好久不见. 提交于 2020-03-04 20:50:53
问题 The data entered in the form is not saving in the database and it is not showing any errors. Iam trying to create an exam with atleast one question, using ExamModelForm and QuestionFormset. After entering exam details and questions in create_exam_with_questions.html, the create button is not saving the data into the database views.py from django.shortcuts import render from django.shortcuts import redirect from django.http import HttpResponseRedirect, HttpResponse from .forms import