Re: [Django] #34168: Add support for list of parameters to the QuerySet.raw().

3 views
Skip to first unread message

Django

unread,
Nov 21, 2022, 4:55:14 AM11/21/22
to django-...@googlegroups.com
#34168: Add support for list of parameters to the QuerySet.raw().
-------------------------------------+-------------------------------------
Reporter: Marek Rouchal | Owner: nobody
Type: New feature | Status: closed
Component: Database layer | Version: 4.1
(models, ORM) |
Severity: Normal | Resolution: wontfix
Keywords: | Triage Stage:
| Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------

Comment (by Marek Rouchal):

The specific problem I am facing is that I need to access an existing
database whose schema I cannot alter; I used the Django tool to extract
the tables to create models.py, which worked great, and I already hacked
the model definitions, e.g. to replace a simple IntegerField with a
ForeignKey. But there are specific tables, where there is an IntegerField
which may contain a ForeignKey from more than one table (think of a group
and a user table; whether it is a user or a group, is defined by another
column):

class Permission(models.Model):
...
user_or_group_id = models.IntegerField(db_column='user_or_group_id',
blank=True, null=True)
is_group = models.IntegerField(db_column='is_group', blank=True,
null=True)


So what I would need here is something like a union on ForeignKey (coming
from either a User or a Group table).
So I used raw SQL for the required joins; I have not been able to
formulate a Django queryset to join on a field which is not modeled with
ForeignKey.
That is why I was asking for some better support of raw SQL...

--
Ticket URL: <https://code.djangoproject.com/ticket/34168#comment:2>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

Reply all
Reply to author
Forward
0 new messages