1

I am new to django and I have difficulty in constructing django query. Can anyone please help me to construct this query into django query?

SELECT DISTINCT mt.ID_Number 
FROM measurement_test mt 
WHERE mt.Start_Date IN('2012-02-15','2012-06-14') 
AND mt.ID_Number != ''

2 Answers 2

3

Assuming "measurement_test" is the object the models the relevant table.

measurement_test.objects.values_list(ID_Number).filter(Start_Date__in=('2012-02-15','2012-06-14')).exclude(ID_Number='').distinct()
Sign up to request clarification or add additional context in comments.

Comments

1

You can use the following,

measurement_test.objects.filter(~Q(ID_Number=''), Start_Date__in=['2012-02-15','2012-06-14']).values('ID_Number').distinct()

2 Comments

This is not a valid Django query. You can't use != in filter calls.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.