modelform

How to save Django ModelFormSet?

亡梦爱人 提交于 2021-02-07 20:31:37
问题 I'm quite desperate now and I cannot figure this out. To me it should be easy to do, but I have not come across any answers that explains this. Two models with no foreign keys between them: class Employee(models.Model): surname = models.CharField(max_length=100) name = models.CharField(max_length=100) class Salary(models.Model): date = models.DateField(auto_now_add=True) surname = models.CharField(max_length=100) name = models.CharField(max_length=100) salary = models.DecimalField(max_digits

Django how to enter multiple records on one form

冷暖自知 提交于 2021-02-07 08:00:27
问题 I am writing a calendar app with the following models: class CalendarHour(models.Model): ''' Each day there are many events, e.g. at 10 am, the framer orders material, etc. ''' day_id = models.ForeignKey(CalendarDay) time = models.TimeField() work = models.TextField() def __unicode__(self): return 'work that took place at {work_time}'.format(work_time = self.time) class CalendarDay(models.Model): ''' Each project has so many daily logs. But, each daily log belongs to only one project

Django how to enter multiple records on one form

心已入冬 提交于 2021-02-07 07:58:22
问题 I am writing a calendar app with the following models: class CalendarHour(models.Model): ''' Each day there are many events, e.g. at 10 am, the framer orders material, etc. ''' day_id = models.ForeignKey(CalendarDay) time = models.TimeField() work = models.TextField() def __unicode__(self): return 'work that took place at {work_time}'.format(work_time = self.time) class CalendarDay(models.Model): ''' Each project has so many daily logs. But, each daily log belongs to only one project

How can I make chained multiple choice fields in Django with JQuery?

我们两清 提交于 2021-01-29 16:27:17
问题 I want to make a chained multiple choice field. I have working code for chained dropdown boxes below. I want to be able to choose more than one option at each level and have the next level return all records for each of the selected values. How can I make this happen? (my code is not very DRY, so appreciate any notes on that as well, but that is secondary) models.py class Nace_Level_1(models.Model): code = models.CharField(max_length=1) name = models.CharField(max_length=200) short_name =

Django forms dynamic getting author as a logged in user in model forms

给你一囗甜甜゛ 提交于 2020-07-10 09:26:27
问题 I'm trying to make some forms that will allow users to add some objects, delete them or edit but I've stucked with thing like author of model. Let's say we got model Shot which got field author = models.ForeignKey(settings.AUTH_USER_MODEL, on_delete=models.CASCADE) Because I've created custom user model to expand user by some fields that I want, and then we creating modelForm, creating views etc. and finally got form. When we will try to submit this form, it won't add this object submited in

Automatically set logged-in user as the author in django using createview and modelform

╄→尐↘猪︶ㄣ 提交于 2020-05-15 19:38:07
问题 I am building a frontend form that allows someone to post an article without accessing the admin. When the user is logged in, I would like for him/her to be able to write an article. Upon saving, I would like that user to automatically be set as the author of the article. I am at an impasse. Any help would be much appreciated. models.py from django.db import models from django.urls import reverse from django.contrib.auth.models import User from django.utils import timezone class Article