I just solve the issue by modifying the view.py like this
def parentsDetails(request, pk):
    parentObj = Parents.objects.get(parent_id=pk)
    std = Student.objects.filter(std_parents = parentObj.parent_id)
    # std = parentObj.student_set.all()
    context = {'parentObj': parentObj, 'std': std}
    # context = {'parentObj': parentObj}
    return render(request, "students_management_app/parents-single.html", 
context)

Thanks to all for your support
On Saturday, 18 March 2023 at 13:36:50 UTC+1 nef wrote:

> Thanks to all of you for your feedback.
> I am trying the 2 suggestions, but none of it works.
> For the use of the uuid in the view, here is the code:
> def parentsDetails(request, pk):
>     parentObj = Parents.objects.get(parent_id=pk)
>     std = Student.objects.filter(student_id = Parents.parent_id)
>     context = {'parentObj': parentObj, 'std': std}
>     # context = {'parentObj': parentObj}
>     return render(request, "students_management_app/parents-single.html", 
> context)
> Here is the template:
>        {% if std %}
>             {% for student in std %}
>             
>                 <h2>List of students</h2>
>                 <p>{{student.std_matricule}}</p>
>                 <p>{{student.std_firstname}} {{student.std_midlename}} 
> {{student.std_surname}}</p>
>                 <p>{{student.std_sex}}</p>
>
>             {% endfor %}
>         {% endif %}
>         <p>No Student found in the database</p>
> I an having this error
> ValidationError at 
> /parentsDetails/321a4f9c-0ffb-4759-9155-b489dd32ad18/['“<django.db.models.query_utils.DeferredAttribute
>  
> object at 0x0000025FFDF3D600>” is not a valid UUID.']
> Please help.
> Thanks
>  NEF
> On Friday, 17 March 2023 at 09:02:21 UTC+1 Sandip Bhattacharya wrote:
>
>>
>>
>> On Mar 16, 2023, at 2:22 PM, nef <frnc...@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/2c59709f-b6b4-4a03-bb96-60c8989e9dc9n%40googlegroups.com.

Reply via email to