[Answered ]-Get record from multiple tables without foreign key relation django

2👍

I don’t know why you say you don’t have a relationship between those two models. You do: it just uses an char field rather than an ID. That’s still a perfectly valid foreign key. You should declare your UserDomain like this:

class UsersDomains(models.Model):
    domain_email = models.ForeignKey(Users, to_field='email', null=True)

and also add unique=True to the Users.domain field, and now Django will automatically do the right thing.

0👍

maybe this could help –

http://www.caktusgroup.com/blog/2009/09/28/custom-joins-with-djangos-queryjoin/

basically it’s just using the queryset.query.join to add whatever join you want..

Leave a comment