I have something like this in views.py.
if form.is_valid():
ref_user = User.objects.get(
username=form.cleaned_data['referrer'])
if User.objects.filter(username=ref_user).exists():
user = User.objects.create_user(
username=form.cleaned_data['username']
)
direct = DirectReferral.objects.create(
name = user,
referrer = ref_user # New created referrer
)
if DirectReferral.objects.filter(referrer=ref_user).exists():
# Get the referrer of the newly created referrer in DirectReferral database
indirect = IndirectReferral.objects.create(
name = user,
referrer = # This should be the referrer of the newly created referrer
)
How do I make a query or get the referrer of the newly created referrer?
To further understand what I mean please check image below.
I hope you understand my question.