> On Mar 16, 2023, at 2:22 PM, nef <frncse...@gmail.com> wrote: > > class Student(models.Model): > #std_matricule = models.CharField(verbose_name='Student matricule', > max_length=6, null=False, unique=True, primary_key=True) > std_matricule = models.CharField(verbose_name='Matricule', unique=True, > max_length=16, null=False, blank=False, help_text='Matricule of the student') > std_parents = models.ForeignKey(Parents, on_delete=models.DO_NOTHING, > related_name='Parents', unique=False, null=True, blank=True, > verbose_name='Student parents') >
I believe that the “related_name” parameter to ForeignKey is the name of the set of THIS model(Student) in the foreign table(Parents). So it should be, “students”, not “Parents”. Only then will a parent object refer to the set of students related to it by that name. e.g. parent.students. This was a point of confusion for me when I read this the first time as well. https://docs.djangoproject.com/en/4.1/topics/db/queries/#backwards-related-objects Thanks, Sandip -- 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 view this discussion on the web visit https://groups.google.com/d/msgid/django-users/181E8507-B83D-426D-B2AC-C61694D8FDC9%40showmethesource.org.