Hi,
i have three models LeaveBalance, NewLeave and User. I want to pull date from NewLeave and User, basically displaying the data of users that have apply for a leave. I had difficulty figuring out how to accomplish this. my views and model are below.
The view is throwing an errror:
Cannot resolve keyword 'newleave_set' into field. Choices are: date_joined, email, first_name, groups, id, is_active, is_staff, is_superuser, last_login, last_name, leave_balance, logentry, newleave, password, profile, user_permissions, username | |
Exception Location: | /root./virtualenvs/eleave/local/lib/python2.7/site-packages/django/db/models/sql/query.py in names_to_path, line 1352 |
Python Executable: | /root./virtualenvs/eleave/bin/python |
views.py
def Allleaves(request):
allleave=User.objects.filter(newleave_set__isnull=False).distinct()
return render(request,'allleave.html',locals())
allleave=User.objects.filter(newleave_set__isnull=False).distinct()
return render(request,'allleave.html',locals())
models.py
class Leave_Balance(models.Model):
user=models.OneToOneField(User,on_delete=models.CASCADE,primary_key=True,)
Monthly_entitlement=models.FloatField(null=True, blank=True, default=None)
Monthly_consumption=models.FloatField(null=True, blank=True, default=None)
Leave_current_balance= models.FloatField(null=True, blank=True, default=None)
leave_encashment= 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='')
dp=(
('test','test'),
('test1','test1'),
)
department=models.CharField(max_length=100,choices=dp,blank=False,default='')
Start_Date=models.DateField(null=True, blank=False)
End_Date=models.DateField(null=True, blank=False)
Total_working_days=models.FloatField(null=True, blank=False)
Reason=models.TextField(max_length=1000,null=True, blank=False)
def __unicode__(self):
return self.Leave_type
user=models.OneToOneField(User,on_delete=models.CASCADE,primary_key=True,)
Monthly_entitlement=models.FloatField(null=True, blank=True, default=None)
Monthly_consumption=models.FloatField(null=True, blank=True, default=None)
Leave_current_balance= models.FloatField(null=True, blank=True, default=None)
leave_encashment= 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='')
dp=(
('test','test'),
('test1','test1'),
)
department=models.CharField(max_length=100,choices=dp,blank=False,default='')
Start_Date=models.DateField(null=True, blank=False)
End_Date=models.DateField(null=True, blank=False)
Total_working_days=models.FloatField(null=True, blank=False)
Reason=models.TextField(max_length=1000,null=True, blank=False)
def __unicode__(self):
return self.Leave_type
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+unsubscribe@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-y52yvOyEbKdQe0SODWAJLR6WB_S91M6DzLTBU2xYGC_eg%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.
No comments:
Post a Comment