allow blank form input, use clean func to keep old val
This commit is contained in:
parent
242067e46c
commit
3da5bf052e
3 changed files with 26 additions and 1 deletions
|
@ -49,6 +49,11 @@ class AddEditTaskForm(ModelForm):
|
|||
|
||||
note = forms.CharField(widget=forms.Textarea(), required=False)
|
||||
|
||||
def clean_created_by(self):
|
||||
"""Keep the existing created_by regardless of anything coming from the submitted form.
|
||||
If creating a new task, then created_by will be None, but we set it before saving."""
|
||||
return self.instance.created_by
|
||||
|
||||
class Meta:
|
||||
model = Task
|
||||
exclude = []
|
||||
|
|
20
todo/migrations/0011_auto_20190724_1130.py
Normal file
20
todo/migrations/0011_auto_20190724_1130.py
Normal file
|
@ -0,0 +1,20 @@
|
|||
# Generated by Django 2.1.8 on 2019-07-24 11:30
|
||||
|
||||
from django.conf import settings
|
||||
from django.db import migrations, models
|
||||
import django.db.models.deletion
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('todo', '0010_attachment'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AlterField(
|
||||
model_name='task',
|
||||
name='created_by',
|
||||
field=models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.CASCADE, related_name='todo_created_by', to=settings.AUTH_USER_MODEL),
|
||||
),
|
||||
]
|
|
@ -78,9 +78,9 @@ class Task(models.Model):
|
|||
created_by = models.ForeignKey(
|
||||
settings.AUTH_USER_MODEL,
|
||||
null=True,
|
||||
blank=True,
|
||||
related_name="todo_created_by",
|
||||
on_delete=models.CASCADE,
|
||||
editable=False,
|
||||
)
|
||||
assigned_to = models.ForeignKey(
|
||||
settings.AUTH_USER_MODEL,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue