I have the following model:
class Project(models.Model):
name = models.CharField(max_length=200)
class Task(models.Model):
name = models.CharField(max_length=200)
project = models.ForeignKey('Project', on_delete=models.CASCADE,
related_name='tasks')
I want to be able to choose the project for a task during creation and forbid to change it once the task was created.
How do I get Task.project
to be editable during creation but non editable during updating on a database/model level?
Approaches so far:
-
- This works on the admin/form level, not on the database level
Making a field read-only in django admin
- This also works on the admin/form level, no on the database level