On Sat, 2009-08-08 at 07:26 -0700, Lokesh wrote: > Hi, > > Need help in generating the sql query i.e generated by django at > runtime from ORM > > from django.contrib.auth.models import User > class UserBasicDetails(models.Model): > user_id = models.OneToOneField(User, primary_key=True, > to_field='username') > name = models.CharField(null=False, blank=False, max_length=30) > > qs = UserBasicDetails.objects.get > (user_id__email__exact='exam...@djano.com') > > > I got the below search result qs.query.as_sql() > but, this will generate sql for only for result sets (filter) and not > for a single record/value (get) (UserBasicDetails.objects.filter > (user_id__email__exact='exam...@djano.com'))
A get() call is a filter() call with only the first element extracted (if more than one element is returned, it's an error). So just look at the SQL for the equivalent filter() call. Regards, Malcolm --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~----------~----~----~----~------~----~------~--~---