Categories
Development

Django configuration issue

I am new to django and familiarizing it. I have installed django and able to run the server and access the django home page. But when I add the model class I am getting the following error in terminal. RuntimeError: Model class myproject.urls.Board doesn’t declare an explicit app_label and isn’t in an application in INSTALLED_APPS. […]

Categories
Development

How to use distinct() method without applying values() using Django?

I hope the title is enough to understand what i mean is. this is my current code in views.py students = grade.objects.filter(Teacher=m.id).annotate(total_avg=Avg(‘Average’)).prefetch_related(‘Subjects’).order_by(‘Students_Enrollment_Records’).distinct() this is the result: as you can see the 2 ROSE L TRiNIDAD exist, and it didnt compute the final ratings, but when i use the values() students=grade.objects.values(‘Students_Enrollment_Records’).filter(Teacher=m.id).annotate(total_avg=Avg(‘Average’)).prefetch_related(‘Students_Enrollment_Records’).order_by(‘Students_Enrollment_Records’).distinct() the result is the distinct() […]

Categories
Development

How to use filtering data while using distinct method in django?

please help me on my problem I hope my title is enough to understand what I mean, please help me on this problem guys. When I tried this: id_list = grade.objects.filter(Teacher=m.id).values_list(‘Students_Enrollment_Records_id’,flat=True).distinct() I use distinct() to eliminates duplicate rows of Students Enrollment Record from the query results but I wonder why the result is like this: […]

Categories
Development Django

How to use update_or_create on django post_save?

class StudentsEnrolledSubject(models.Model): Students_Enrollment_Records = models.ForeignKey(StudentsEnrollmentRecord, related_name=’+’, on_delete=models.CASCADE, null=True) Subject_Section_Teacher = models.ForeignKey(SubjectSectionTeacher, related_name=’+’, on_delete=models.CASCADE, null=True,blank=True) @receiver(post_save, sender=StudentsEnrollmentRecord) def create(sender, instance, created, *args, **kwargs): teachers = SubjectSectionTeacher.objects.filter(Sections=instance.Section, Education_Levels=instance.Education_Levels, Courses=instance.Courses) for each in teachers: if created or teachers.exists(): print(“if”) StudentsEnrolledSubject.objects.create_or_update( pk=each.id, Students_Enrollment_Records=instance, Subject_Section_Teacher=each ) Inserting data is working perfectly but when I update the existing data it creates […]

Categories
Development Django

How to save all related data using django signals post_save

I just want that if the admin insert the Course(ABM) and Education Level (Grade 11) and Section(Chronicles) it will get all related data in subjectsectionteacher(second picture) and it will automatic save to student enrolled subject(third picture) my problem is only one data save. this is my code in models.py class StudentsEnrollmentRecord(models.Model): Student_Users = models.ForeignKey(StudentProfile, related_name=’students’, […]

Categories
Development Django

How to combine two listview in django admin site

how do i add this table under the table students enrollment record when the admin filter/or click the monthly? this is my code in model.py class StudentsEnrollmentRecord(models.Model): Student_Users = models.ForeignKey(StudentProfile, related_name=’students’, on_delete=models.CASCADE,null=True) School_Year = models.ForeignKey(SchoolYear, related_name=’+’, on_delete=models.CASCADE, null=True, blank=True) Courses = models.ForeignKey(Course, related_name=’+’, on_delete=models.CASCADE, null=True, blank=True) Section = models.ForeignKey(Section, related_name=’+’, on_delete=models.CASCADE, null=True,blank=True) Payment_Type = models.ForeignKey(PaymentType, […]

Categories
Development

two forloop in 1 table row

<table> </table> \views teacher = SubjectSectionTeacher.objects.filter(Education_Levels__in=studentenroll.values_list(‘Education_Levels’)) roomsched = SubjectRoomSchedule.objects.filter(Subject_Section_Teacher__in=teacher) return render(request, ‘Homepage/enrollmentrecords.html’,{,”teacher”:teacher,”roomsched”:roomsched}) how do i make it properly formatted in table row just like this in the example shown below. please help me…. Subject Teacher Room math teachername room512 here is my model, class SubjectRoomSchedule(models.Model): Subject_Section_Teacher = models.ForeignKey(SubjectSectionTeacher, related_name=’+’, on_delete=models.CASCADE,null=True) Classroom =models.ForeignKey(Room, related_name=’+’, on_delete=models.CASCADE,null=True) class […]

Categories
Development Django

how to filter two foreign keys in django

int() argument must be a string, a bytes-like object or a number, not ‘ForwardManyToOneDescriptor’ class StudentsEnrollmentRecord(models.Model): Student_Users = models.ForeignKey(StudentProfile, related_name=’+’, on_delete=models.CASCADE,null=True) School_Year = models.ForeignKey(SchoolYear, related_name=’+’, on_delete=models.CASCADE, null=True, blank=True) Courses = models.ForeignKey(Course, related_name=’+’, on_delete=models.CASCADE, null=True, blank=True) Section = models.ForeignKey(Section, related_name=’+’, on_delete=models.CASCADE, null=True,blank=True) Payment_Type = models.ForeignKey(PaymentType, related_name=’+’, on_delete=models.CASCADE, null=True) Education_Levels = models.ForeignKey(EducationLevel, related_name=’gradelevel’, on_delete=models.CASCADE,blank=True,null=True) Remarks = models.TextField(max_length=500,null=True,blank=True) […]

Categories
Development

How can i filter the relationship between parents and child?

Here is my code: \\models class ParentsProfile(models.Model): Fathers_Firstname = models.CharField(max_length=500,null=True,blank=True) Fathers_Middle_Initial = models.CharField(“Middle Initial”,max_length=500,null=True,blank=True, help_text=”Father”) Fathers_Lastname = models.CharField(max_length=500,null=True,blank=True) class ChildProfile(models.Model): Firstname = models.CharField(max_length=500,null=True,blank=True) Middle_Initial = models.CharField(max_length=500,null=True,blank=True) Lastname = models.CharField(max_length=500,null=True,blank=True) Parent_Users = models.ForeignKey(ParentsProfile, related_name=’+’, on_delete=models.CASCADE,null=True,blank=True,) \\and this is my view def Parents_login_form(request): students = StudentProfile.objects.all() return render(request, ‘Homepage/parentsprofile.html’, {“students”: students}) How do I filter the relationship […]