| | 1581 | |
|---|
| | 1582 | Falling back to raw SQL |
|---|
| | 1583 | ======================= |
|---|
| | 1584 | |
|---|
| | 1585 | If you find yourself needing to write an SQL query that is too complex for |
|---|
| | 1586 | Django's database-mapper to handle, you can fall back into raw-SQL statement |
|---|
| | 1587 | mode. |
|---|
| | 1588 | |
|---|
| | 1589 | The preferred way to do this is by giving your model custom methods or custom |
|---|
| | 1590 | manager methods that execute queries. Although there's nothing in Django that |
|---|
| | 1591 | *requires* database queries to live in the model layer, this approach keeps all |
|---|
| | 1592 | your data-access logic in one place, which is smart from an code-organization |
|---|
| | 1593 | standpoint. For instructions, see `Executing custom SQL`_. |
|---|
| | 1594 | |
|---|
| | 1595 | Finally, it's important to note that the Django database layer is merely an |
|---|
| | 1596 | interface to your database. You can access your database via other tools, |
|---|
| | 1597 | programming languages or database frameworks; there's nothing Django-specific |
|---|
| | 1598 | about your database. |
|---|
| | 1599 | |
|---|
| | 1600 | .. _Executing custom SQL: http://www.djangoproject.com/documentation/model_api/#executing-custom-sql |
|---|