I have few things to ask for custom queries in Django
- DO i need to use the DB table name in the query or just the Model name
- if i need to join the various tables in raw sql. do i need to use db field name or model field name like
Person.objects.raw('SELECT id, first_name, last_name, birth_date FROM Person A
inner join Address B on A.address = B.id
')
or B.id = A.address_id
asked Nov 1, 2012 at 6:54
Mirage
31.7k64 gold badges174 silver badges266 bronze badges
1 Answer 1
You need to use the database's table and field names in the raw query--the string you provide will be passed to the database, not interpreted by the Django ORM.
answered Nov 1, 2012 at 6:58
Jamey Sharp
8,5322 gold badges33 silver badges43 bronze badges
Sign up to request clarification or add additional context in comments.
Comments
lang-py