I have the following models.
class UserBudget(models.Model):
cat = models.ForeignKey('preference.Category', on_delete=models.CASCADE)
user = models.ForeignKey(settings.AUTH_USER_MODEL, on_delete=models.CASCADE)
budget = models.DecimalField(default=0.00, decimal_places=2, max_digits=20)
is_active = models.BooleanField(default=True)
created_at = models.DateTimeField(auto_now_add=True)
updated_at = models.DateTimeField(auto_now=True)
class Category(models.Model):
name = models.CharField(max_length=255)
created_at = models.DateTimeField(auto_now_add=True)
updated_at = models.DateTimeField(auto_now=True)
is_active = models.BooleanField(default=True)
class UserCategory(models.Model):
user = models.ForeignKey(settings.AUTH_USER_MODEL, on_delete=models.CASCADE)
# cat_style_id = models.ForeignKey('preference.CategoryStyle',
on_delete=models.CASCADE)
cat = models.ForeignKey('preference.Category', null=True,
on_delete=models.CASCADE)
# style = models.ForeignKey('preference.Style', null=True,
on_delete=models.CASCADE)
is_active = models.BooleanField(default=True)
created_at = models.DateTimeField(auto_now_add=True)
updated_at = models.DateTimeField(auto_now=True)
I want to perform the following query.
select uc.id as cat_id, uc.user_id cat_user, ub.user_id as budget_user,
ub.cat_id as budget_cat from user_categories as uc
left outer join user_budget as ub on uc.id = ub.cat_id
where uc.user_id = 2
Expecting follwoing result
--
You received this message because you are subscribed to the Google Groups
"Django users" 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].
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit
https://groups.google.com/d/msgid/django-users/a08b6026-5325-418b-b9ae-5b2b1e8501ab%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.