Skip to content

Instantly share code, notes, and snippets.

Last active Apr 19, 2022
What would you like to do?
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'
from django.db.models import Q
from django.http import HttpResponse
from app.models import Employee
def index(request):
queryset = Employee.objects.filter(
| Q(fullName1__icontains="Steven")
| Q(workEmail__icontains="Steven")
| Q(mapping__new_id__icontains="Steven")
).values("id", "fullName1", "workEmail")
return HttpResponse("Hello, world.")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment