The path will be this situation. Work teams enter their account and fill out a form on the work done. At the end of the month, the foreman enters his account and sees all these records, he must confirm them (checkbox), it is possible to correct them, and write comments. Let the model look like this:

class TaskList(models.Model): worker = models.Charfield(max_length=50) task = models.CharField(max_length=20) date = models.DateField() signed = models.BooleanField(default=0) comment = models.CharField(max_length=200) 

Forms:

 class TaskFormWorker(ModelForm): class Meta: model = TaskList fields = ['task', 'date'] class TaskFormManager(ModelForm): class Meta: model = TaskList fields = [f.name for f in TaskList._meta.get_fields()] 

That is, the Brigadier presses the task in the task list and falls into the detail available for editing.

How to make the data for the selected task from the database fall into the form?

For example, I will pass the task ID through the URL, get a TaskList instance, but how can I send it to the form? ..

    1 answer 1

    You can create a form from a model. To do this, use the standard class Django ModelForm

    Example from documentation

     >>> from django.forms import ModelForm >>> from myapp.models import Article # Create the form class. >>> class ArticleForm(ModelForm): ... class Meta: ... model = Article ... fields = ['pub_date', 'headline', 'content', 'reporter'] # Creating a form to add an article. >>> form = ArticleForm() # Creating a form to change an existing article. >>> article = Article.objects.get(pk=1) >>> form = ArticleForm(instance=article) 

    When rendering a ModelForm with a passed model instance, you will receive a form with filled data.

    Documentation: