1👍
✅
First of all you should use ForeignKey
fields for role_id
in Custom_user_model
and user_id
in Deal
. The same is probably true for some of the other _id
fields in your models.
class Custom_user_model(User):
...
role = models.ForeignKey('Role')
...
class Deal(models.Model):
...
user = models.ForeignKey('Custom_user_model')
...
After that you can do your query like this:
# get deals from users with role_id=2
query = Deal.objects.filter(user__role_id=2)
# add filter for deals created by that user created between
start_date, end_date = week_magic(date.today())
query = query.filter(created__between=(start_date, end_date))
Source:stackexchange.com