For example I have two models. What I get confused here is it will be better to store department_id directly on the Sale model or use product.department whenever you need it.
The use case for the department in sales model can be, filter sales by department, reports sales of department or so on.
class Product():
name = models.CharField()
department = models.ForeignKey(Department)
class ProductSale()
product = models.ForeignKey(Product)
department = models.ForeignKey(Department)
# other fields
Or just
class ProductSale()
product = models.ForeignKey(Product)
# other fields
Which query would be more efficient.
ProductSale.objects.filter(department_id=kwargs.get("department_id"))
Or
ProductSale.objects.filter(product__department_id=kwargs.get("department_id"))
I think second query is less efficient but also i think there's no need for storing department_id in the ProductSale model since we can get department_id through product.(Department will be the same of product for sale as well)