django-views

Django - form.save() is not creating ModelForm

我怕爱的太早我们不能终老 提交于 2020-05-04 05:29:31
问题 In my Django application users send feedback about task. I'm creating this form with ModelForm , and after form.save() my object is not creating and is not uploading to database. Here are my codes: views.py : @login_required(login_url='sign_in') def task_details(request, slug): if slug: task = get_object_or_404(Task, slug=slug) today = datetime.now().date() deadline = task.task_deadline.date() time_left = deadline - today form = CreateFeedbackForm() if request.method == 'POST': form =

Json Post from Django to Camunda

二次信任 提交于 2020-04-30 11:18:19
问题 Further to my earlier post yesterday: Post request to external Rest Service using Django - use returned json to update model I have managed to post data to camunda using Django - request.post. Using the following script: payload = "{\n \"businessKey\": \"SomeValue\",\n \"variables\": {\n \"Organisation_ID\": {\n \"value\": \"SOmeUUID\",\n \"type\": \"String\"\n },\n \"UserID\": {\n \"value\":\"Some User ID\",\n \"type\": \"String\"\n }\n }\n}" However when I start to use variables from the

Json Post from Django to Camunda

五迷三道 提交于 2020-04-30 11:16:25
问题 Further to my earlier post yesterday: Post request to external Rest Service using Django - use returned json to update model I have managed to post data to camunda using Django - request.post. Using the following script: payload = "{\n \"businessKey\": \"SomeValue\",\n \"variables\": {\n \"Organisation_ID\": {\n \"value\": \"SOmeUUID\",\n \"type\": \"String\"\n },\n \"UserID\": {\n \"value\":\"Some User ID\",\n \"type\": \"String\"\n }\n }\n}" However when I start to use variables from the

One To Many and models

时光毁灭记忆、已成空白 提交于 2020-04-18 05:44:09
问题 i am trying to build my first project, a CRM website to handle orders and inventory. and i got stuck, i was able to link orders to customer. but when i try to build order that contain multi items. for some reason i didn't find a way to do it. hope you can assist me. so I have User>>Order>>Multi Items. questions: 1) does the best practice here is just use ForeignKey ? this my model's code: from django.db import models class Customer(models.Model): name = models.CharField(max_length=200, null

Django/Python Stripe stripeToken doesn't seem to load/work properly

为君一笑 提交于 2020-04-18 05:36:12
问题 I am trying to charge a subscription on Stripe API in test-mode and my charge keeps getting declined. Everything seems to be working fine, except I cannot retrieve the "stripeToken" via POST. I tested this by printing the various variables I need and they all work fine... but when it comes to printing stripeToken, I get this error: MultiValueDictKeyError at /memberships/payment/ 'stripeToken' Request Method: POST Request URL: http://127.0.0.1:8000/memberships/payment/ Django Version: 2.2

How to stop __init__ of a class based view executing twice in django?

让人想犯罪 __ 提交于 2020-04-18 03:44:11
问题 I have shuffled the questions and corresponding options in the exam. Once student has wriiten the exam score will be displayed, and I want to show the student their answer sheet in the same way as they have seen while writing the exam with their answers and correct answers. So I decided to use random.seed(). Why init () is executing twice ? [12/Mar/2020 14:08:58] "GET /exam/4/ HTTP/1.1" 200 11103 [12/Mar/2020 14:41:15] "GET / HTTP/1.1" 200 5059 init seed = 13 student now writing the exam with

django forms exclude values from choicefield that are already into database

↘锁芯ラ 提交于 2020-04-16 02:37:25
问题 I want to exclude those options from the ChoiceField in the forms that has been already selected and are into the database. Below is the Code. models.py SEMESTER_CHOICES = ( ("1", "1"), ("2", "2"), ("3", "3"), ("4", "4"), ("5", "5"), ("6", "6"), ("7", "7"), ("8", "8"), ) class Publish(models.Model): dates = models.CharField(max_length=255, choices = SEMESTER_CHOICES) def __str__(self): return self.dates form.py SEMESTER_CHOICES = ( ("1", "1"), ("2", "2"), ("3", "3"), ("4", "4"), ("5", "5"), (

django forms exclude values from choicefield that are already into database

懵懂的女人 提交于 2020-04-16 02:36:54
问题 I want to exclude those options from the ChoiceField in the forms that has been already selected and are into the database. Below is the Code. models.py SEMESTER_CHOICES = ( ("1", "1"), ("2", "2"), ("3", "3"), ("4", "4"), ("5", "5"), ("6", "6"), ("7", "7"), ("8", "8"), ) class Publish(models.Model): dates = models.CharField(max_length=255, choices = SEMESTER_CHOICES) def __str__(self): return self.dates form.py SEMESTER_CHOICES = ( ("1", "1"), ("2", "2"), ("3", "3"), ("4", "4"), ("5", "5"), (

How to place a django form in a nav bar so that it appears on every page?

こ雲淡風輕ζ 提交于 2020-04-16 02:27:33
问题 I have a form whose queryset depends on request.user, and whose initial value depends on a session key. The primary models are User (slight modification of default User model) and Account, with a many-to-many relationship between them. The form allows a User to change the Account that he/she is viewing, and that choice must persist as the User navigates the site. The form works fine when created in a single view and passed to a single template, but I want the form to appear in the top

Assertion error while testing Django views

风流意气都作罢 提交于 2020-04-07 07:17:37
问题 This is my testing function for views.py which I have mention below: def test_operation_page(self): url = reverse('operation') response = self.client.get(url) self.assertEqual(response.status_code, 200) self.assertTemplateUsed(response, 'abc.html') self.assertContains(response, '<b>BOOK id having certain title:</b>') This is the error I am having while testing my views AssertionError: Database queries to 'default' are not allowed in SimpleTestCase subclasses. Either subclass TestCase or