1👍
you can do this by executing a custom SQL from django but the main problem I see here is the way the models are been handled, it would be a lot easier if you mixed all this user foreign keys to be in the UserProfile, for example:
class UserProfile(models.Model):
user = fields.OneToOneField(User)
company = fields.ForeignKey(Company)
options = fields.ForeignKey(Options)
notification_settings = fields.ForeignKey(NotifySettings)
...
This way you can use the ORM django brings with more ease. In my opinion it would be faster for you to create a migration instead of this huge query.
Source:stackexchange.com