#29551: My use-case of QuerySet.extra(): Join two models without explicit
relation
-----------------------------------------+--------------------------------
Reporter: Bowser | Owner: nobody
Type: Uncategorized | Status: new
Component: Uncategorized | Version: 2.0
Severity: Normal | Keywords: QuerySet.extra
Triage Stage: Unreviewed | Has patch: 0
Needs documentation: 0 | Needs tests: 0
Patch needs improvement: 0 | Easy pickings: 0
UI/UX: 0 |
-----------------------------------------+--------------------------------
Hello,
I'm reporting here, as suggested in the docs, my use-case of
QuerySet.extra() method, looking if there is any way to make it in a
different way.
My django app is inter-operating with an independent third-party email
program which created and filled independently some tables in a separate
DB.
In order to obtain data from that independent tables in my django system I
needed to map those tables in a new django model using the command
inspectdb of manage.py. This worked very well with minimal corrections and
let me the opportunity to get successfully the data from that tables in my
Django system.
My need of QuerySet.extra() came out when I needed to join that special
model with other (regular) models of my django system with a field (the
email address the sender used) that can be put in relation with some of
the customers of my system (but of course it may not be too if there is no
relation if the sender email is unknown)
Obviuosly I counldn't put a normal ForeignKey on that model nor I can
change the structure of the tables because it could block my third party
email system from working properly so I couldn't put a direct regular
relation between those models.
This ended in the insertion of the .extra() method in the main queryset of
the ModelAdmin (I'm testing that system in the admin panels for now and is
working properly with the target of using it in my main app too):
{{{#!python
def get_queryset(self, request):
return super(InboxAdmin,self).get_queryset(request).extra(
select={'customer': 'customer_id'},
where=["SenderEmail = email"],
tables=['Customers_customer']
)
}}}
This is working well but I wonder if this can be done in a better way.
So my question practically is if there is any way in Django to join two
models even when there is no explicit relation between them (OneToOne,
ManyToMany or ForeignKey) that I can't insert.
Any idea?
Thank you
--
Ticket URL: <https://code.djangoproject.com/ticket/29551>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
--
You received this message because you are subscribed to the Google Groups
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/django-updates/049.002f949821e1aacfa4e9d50d84f46c40%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.