开发者

Django Associations with the user model

开发者 https://www.devze.com 2023-03-23 14:05 出处:网络
Ho开发者_高级运维w can I associate lists apps Listing model with an user. User has_many lists.

Ho开发者_高级运维w can I associate lists apps Listing model with an user. User has_many lists.

What shall I include in my List model for being able to use models.ForeignKey(User)


Here you go (Although you should just look at the Django DOcs the next Time):

from django.db import models
from django.contrib.auth.models import User

class Listing(models.Model):
    user = models.ForeignKey(User)

Hope this helps

0

精彩评论

暂无评论...
验证码 换一张
取 消