Home > Net >  How to Convert This Sql Query TO Django Query
How to Convert This Sql Query TO Django Query

Time:01-09

I want Get UID Based on Email Filtering Like "(select Uid From User_master where email = 'xyz.gmail.com')" How to Convert This Sql Query TO Django Query

CodePudding user response:

assuming you have a model that contains the 'email', 'user_master', 'id', then beneath the model (but within its tab) you can try something like the following (the @property decorator enables one to use the function as though its a part of the model)

@property
def myEmailerId(self):
    queryset = self.email.all().values_list('user_master__id', flat=True)
    return queryset

CodePudding user response:

This will retrieve all User_master objects with the specified email and only retrieve the Uid

from .models import User_master

user_uid = User_master.objects.filter(email='xyz.gmail.com').values_list('Uid', flat=True)[0]

  •  Tags:  
  • Related