Issue
I'm a newbie in django and doing my very first food delivery website. I've not created any model for user auth table but created model for my menu table. now i want to create a model for order table where i want to keep both menu id and user id as foreign key.. is it possible any way or i must create a model for user table also?
Solution
django is already have a User model ready for you , you can use it as below:
#first import the user model
from django.contrib.auth.models import User
# then add it as a ForeignKey
class Order(models.Model):
user = models.ForeignKey(User,on_delete=models.CASCADE)
menu = models.ForeignKey(Menu,on_delete=models.CASCADE)
Answered By - zain al-abdeen
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.