I have Company and CompanyUser models. CompanyUser has 1:1 relationship with the django's auth User model. Every user is part of some company, so I have a ForeignKey field (Company) in the CompanyUser model:
class CompanyUser(models.Model):
Company = models.ForeignKey(Company)
User = models.OneToOneField(User)
Now I want to create some html tables to view and filter the data about Sales, Products, etc. I'm using django-tables2 and that works great.
Now let's say I want to see the Sales of a particular Product. So I need a dropdown that contains all Products of the Company that the user belongs to.
I've have created the forms.py file in my app:
from django import forms
class SaleFilterForm(forms.Form):
product_id = forms.ChoiceField(queryset=Product.objects.all(Company=???))
...
...
So my question is. How to get the current user, when I'm inside forms.py file? I don't have the "request" object there..