I want to create a Relational database with auth_user table which is automatically created in django after migrations(database is postgresql). I have created a table with class named order. My models.py looks like this
Models.py
from django.db import models
from django.contrib.auth.models import User
# Create your models here.
class order(models.Model):
user = models.ForeignKey(User, on_delete=models.CASCADE)
product = models.CharField(max_length=50)
price = models.IntegerField()
now I want to link the user id with table order with user_id. And my views.py looks like this. views.py
def order_Data(request):
product = request.POST['product']
price = request.POST['price']
orders = order(product=product,price=price)
orders.save()
messages.info(request,'Data saved')
return render(request,'home.html')
I think I have linked tables properly but in user_id of order table is setting as null and giving me error. I dont know what to do now. Please Help me out (Iam also a learner in Django). Thank you in advance.