2👍
✅
Use None
as the default argument and then check in the body of the function for None
.
def supplier_default_product(region, supplier=None):
if supplier is None:
supplier = region.default_supplier.id
default_product_instance = Product.objects.get(name=default_product, supplier=supplier)
You can’t reference an attribute of another argument, because the default argument values are set at define time, which only happens once.
Source:stackexchange.com