def view_transaction(request):
print(request.user)
user_transactions = Transactions.objects.filter(user_account = request.user)
return render(request,'transactions.html',{'user_transactions':user_transactions})
is the above code correct or not, i think when it check wheather user login is not present here.
models.py
class User(models.Model):
name = models.CharField(max_length=45)
phone = models.CharField(max_length=45)
account_number = models.CharField(max_length=45,primary_key=True,blank=False,unique=True)
user_id = models.CharField(max_length=45,unique=True)
password = models.CharField(max_length=45)
confirm_password = models.CharField(max_length=45)
class Transactions(models.Model):
transaction_number = models.AutoField(primary_key=True)
user_account = models.ForeignKey(User,on_delete=models.CASCADE)
date_of_transaction = models.DateField()
transaction_type = models.CharField(max_length=20, choices=TRANSACTION_TYPES)
transaction_medium = models.CharField(max_length=20, choices=TRANSACTION_MEDIUM)
transaction_amount = models.DecimalField(max_digits=10,decimal_places=2)
when i login using userid and password ,it shows some details about customer. I want transaction details in transactions.html,but i didn’t get any, instead i got error like anonymous user.