You could follow the steps below.
- Create a view function that takes the search parameter as a keyword
argument.
- Use the QuerySet object to filter the Skill table by the search
parameter.
- Use the prefetch_related() method to load the Recruitment objects
associated with the Skill objects.
- Return the Recruitment objects.
I mean something like this
def get_recruitments_by_skill(request, skill):
# Get the skills that match the search parameter.
skills = Skill.objects.filter(sk1=skill)
# Prefetch the recruitments associated with the skills.
skills.prefetch_related('recruitment')
# Return the recruitments.
return render(request, 'recruitments.html', {'skills': skills})
Thanks & Regards,
---------------------
Mayank Tripathi
"Do what you can, with what you have, where you are -by Theodore Roosevelt"
On Sat, May 13, 2023 at 4:56 PM Oduwa Imade <[email protected]> wrote:
> Hello Guys! How do I write a model query in django python to get the User
> details(Recruitment) when i pass a search parameter( skill) to the Skill
> table?
>
> class Recruitment(models.Model):
> fname = models.CharField(max_length=50)
> lname = models.CharField(max_length=50)
> address = models.CharField(max_length=100)
> phone = models.IntegerField()
> email = models.CharField(max_length=50)
> password = models.CharField(max_length=30)
>
> class CV(models.Model):
> summary = models.TextField()
> f_key_REC = models.ForeignKey(Recruitment, related_name='cv',
> on_delete=models.CASCADE)
>
> class Skill(models.Model):
> sk1 = models.CharField(max_length=100, default=None)
> sk2 = models.CharField(max_length=100, default=None)
> sk3 = models.CharField(max_length=100, default=None)
> fk_sCV = models.ForeignKey(CV, related_name='skill',
> on_delete=models.CASCADE)
>
> --
> 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 [email protected].
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/c381af8c-e2f7-41b8-ae48-71f389a23459n%40googlegroups.com
> <https://groups.google.com/d/msgid/django-users/c381af8c-e2f7-41b8-ae48-71f389a23459n%40googlegroups.com?utm_medium=email&utm_source=footer>
> .
>
--
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 [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/django-users/CALQo0B8sRLh-ivziMQSdLN_qqbgn4XyOQS%2BXNkWaH%2BzKm%3D376g%40mail.gmail.com.