Last active
April 19, 2022 04:04
-
-
Save lybcyd/b83084303657134d7cff52597ae315f9 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from django.db import models | |
class Employee(models.Model): | |
id = models.CharField(max_length=255, primary_key=True) | |
fullName1 = models.CharField(max_length=255) | |
workEmail = models.CharField(max_length=255) | |
class Meta: | |
db_table = 'employees' | |
class IdMapping(models.Model): | |
user = models.ForeignKey(Employee, db_constraint=False, on_delete=models.DO_NOTHING, related_name='mapping') | |
new_id = models.CharField(max_length=255) | |
class Meta: | |
db_table = 'id_mapping' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from django.db.models import Q | |
from django.http import HttpResponse | |
from app.models import Employee | |
def index(request): | |
queryset = Employee.objects.filter( | |
Q(id__icontains="Steven") | |
| Q(fullName1__icontains="Steven") | |
| Q(workEmail__icontains="Steven") | |
| Q(mapping__new_id__icontains="Steven") | |
).values("id", "fullName1", "workEmail") | |
print(queryset.query) | |
return HttpResponse("Hello, world.") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment