Adding/deleting fields in the same ModelForm django

45 Views Asked by At

I have little experience in django so I would really appreciate your help!

In general, I have created a ModelForm which depending on the users who is logged in, he changes some values in the field. So consider that this form is being edited about 5 times by 5 different users.

I would like to show a specific field in the template (and view) only when the third user is logged in.

My model is :

 class Task(models.Model): 
      Taskdetails = models.CharField(max_length=500, null=True)
      asset = models.ForeignKey('Asset', null=True)
      failure = models.ForeignKey('Failure', null=True)
      cause = models.ForeignKey('Cause', null=True)
      Created_task_date = models.DateTimeField(default=timezone.now, null=True)
      employee = models.ForeignKey("auth.User", null = True)

and also i have created this ModelForm

  class Meta:
    model = Task
    fields = ('Taskdetails', 'asset', 'failure', ,'employee','cause',)

Also I have 5 edititions of the TaskForm in which is user edits something.

The thing I am trying to do is to show the cause field only in the third form.

I tried to exclude the value but nothing apperas. If i include the field cause (just like above), I must "pass" it in the template in order to be edited from the first user (otherwise the task_form is not saved)

I hope I became clear.

I would really appreciate your help.

0

There are 0 best solutions below