Thanks,
The Leave_current_balance is from Leave_Balance model which why i haven't
included it. I am not sure how to fix that.
Sum
On Fri, Feb 15, 2019 at 12:42 PM Simon Charette <charett...@gmail.com>
wrote:

> Your DirectorForm model form doesn't include 'Leave_current_balance' in
> it's Meta.fields
> hence no form field is generated for it.
>
> Cheers,
> Simon
>
> Le jeudi 14 février 2019 17:50:21 UTC-5, suabiut a écrit :
>>
>> Hi,
>>
>> I have two models many to many relationships, I am trying to update the
>> field using a form. when a leave is submitted the director is notified by
>> email. the director can login to the system to approve the leave using the
>> form. once the leave is approved, I want to adjust the
>> Leave_current_balance field  which in on the LeaveBalance model
>>
>> class LeaveBalance(models.Model):
>>     
>> user=models.OneToOneField(User,on_delete=models.CASCADE,primary_key=True,)
>>     Leave_current_balance= models.FloatField(null=True, blank=True, 
>> default=None)
>>     Year=models.CharField(max_length=100,default='')
>>     def __unicode__(self):
>>              return  self.Year
>>
>>
>> class NewLeave(models.Model):
>>      user=models.ForeignKey(User,default='',on_delete=models.CASCADE)
>>              leave_balance=models.ManyToManyField(Leave_Balance)
>>         leave=(
>>         ('annual','annual'),
>>         ('sick','sick'),
>>
>>      )
>>
>>      
>> Leave_type=models.CharField(max_length=100,choices=leave,blank=False,default='')
>>
>>         Total_working_days=models.FloatField(null=True,  blank=False)
>>         DirAuth=(
>>             ('Pending','Pending'),
>>             ('Approved','Approved'),
>>             ('Rejected','Rejected'),
>>         )
>>
>>      
>> Director_Authorization_Status=models.CharField(max_length=100,choices=DirAuth,default='Pending',blank=False)
>>      Date_Authorized=models.DateField(null=True,blank=False)
>>      
>> Authorized_by_Director=models.CharField(max_length=100,default='',blank=False)
>>
>>         def __unicode__(self):
>>             return  self.Leave_type
>>
>>
>>
>>
>> class DirectorForm(forms.ModelForm):
>>     class Meta:
>>         model=NewLeave
>>         
>> fields=('Director_Authorization_Status','Authorized_by_Director','Date_Authorized',)
>>         widgets={
>>             'Date_Authorized':DateInput()
>>         }
>>
>>
>>
>> This function throw the error: u'Leave_current_balance'
>>
>> def unitDirectorForm(request,id):
>>
>>     if request.method=='POST':
>>
>>         getstaffid=NewLeave.objects.get(id=id)
>>         form = DirectorForm(request.POST, instance=getstaffid)
>>         if form.is_valid():
>>             getstaffid = form.save(commit=False)
>>             getstaffid.save()
>>
>>             total_days = getstaffid.Total_working_days
>>             current_balance = 
>> getstaffid.user.leave_balance.Leave_current_balance
>>             diff_balance = current_balance - total_days
>>             current_balance = diff_balance
>>             current_balance=form.fields['Leave_current_balance']
>>             current_balance.save()
>>             getstaffid.leave_balance.add(current_balance)
>>
>>             return HttpResponse('You have successfuly Authorise the leave')
>>
>>     else:
>>         #getstaffid=NewLeave.objects.get(id=id)
>>         form=DirectorForm()
>>         #c_balance=Leave_Balance.objects.get()
>>         balance_form = leavebbalanceForm()
>>
>>     return render(request,'managerauthorisedform.html',{'form':form})
>>
>> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to django-users+unsubscr...@googlegroups.com.
> To post to this group, send email to django-users@googlegroups.com.
> Visit this group at https://groups.google.com/group/django-users.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/a03bfa6f-f5c8-4f7c-a1de-ba961c4009c0%40googlegroups.com
> <https://groups.google.com/d/msgid/django-users/a03bfa6f-f5c8-4f7c-a1de-ba961c4009c0%40googlegroups.com?utm_medium=email&utm_source=footer>
> .
> For more options, visit https://groups.google.com/d/optout.
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CAPCf-y5EB7MzxO8SF6sWpXDCTVusodC9yt9JN9HhyeTj31temw%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to