Friday, May 29, 2020

Re: filter on multiple tables

Thank You, for your guidance.I think I'm very close to this problem.

Thank you once again.

‪On Fri, May 29, 2020 at 9:56 AM ‫אורי‬‎ <uri@speedy.net> wrote:‬
Hi Soumen,

You can filter on another table by using <table_name>__<field>, for example:

User.objects.filter(profile__profiles__institute_name="Example")

Or:

User.objects.filter(profile__profiles__institute_name__in=["Example 1", "Example 2"])


On Thu, May 28, 2020 at 11:27 PM Soumen Khatua <soumenkhatua258@gmail.com> wrote:
Actually I want to filter all users those are matched with currently logged in users based on location or education details like maybe institute_name or specialization. Is it possible to search in multiple tables?!
I almost spent 2 days but still I stuck in the position.
Any help would be appreciated.

Thank You

Regards,
Soumen


class Location(models.Model):
    name = models.CharField(max_length = 15)

class Profile(models.Model):
    user = models.OneToOneField(
        settings.AUTH_USER_MODEL,
        on_delete = models.CASCADE,
        related_name="profile"
    )
    location = models.ManyToManyField(Location,related_name = 'user_locations')

class Education(models.Model):
    profile = models.ForeignKey(Profile, on_delete=models.CASCADE,related_name="profiles")
    institute_name = models.CharField(max_length = 250)
    specialization = models.CharField(max_length = 100)


--
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 view this discussion on the web visit https://groups.google.com/d/msgid/django-users/CAPUw6WZqX9oqutYfGJqAwCswY_00VfTmf624ypypAr6saS61Nw%40mail.gmail.com.

--
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 view this discussion on the web visit https://groups.google.com/d/msgid/django-users/CABD5YeFfHWDEkTFwMFocApuG3ejYY5QjqHHd_86wNNc-JoWP4g%40mail.gmail.com.

--
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 view this discussion on the web visit https://groups.google.com/d/msgid/django-users/CAPUw6WZGO9bXukP9VX_k%3DOW0U1Vbz_885cH5i%2BhH8n-nFXz%2BQw%40mail.gmail.com.

No comments:

Post a Comment