在Django管理员列表中,链接与对象没有关系的模型
我有两个模型,这些模型没有外键作为关系,但具有常见的用户名列。
class User(models.Model):
password = models.CharField(max_length=255)
email = models.EmailField(unique=True, blank=True)
username = models.CharField(max_length=255)
class SessionUser(models.Model):
username = models.CharField(max_length=255)
last_login = models.DateTimeField(auto_now=True)
我想列出django管理员中的所有用户,并在单个对象上单击一旦列出了所有用户的会话。我们如何链接没有遗体密钥关系的对象?
I have two models which doesn't have foreign key as relation but has the username column common.
class User(models.Model):
password = models.CharField(max_length=255)
email = models.EmailField(unique=True, blank=True)
username = models.CharField(max_length=255)
class SessionUser(models.Model):
username = models.CharField(max_length=255)
last_login = models.DateTimeField(auto_now=True)
I wanted to list all users in Django admin and once clicked on individual object it should list all the session of user. How can we link the object which doesn't have foregien key relationship?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
制作
用户名
模型字段 在用户
模型中唯一。并在用户Admin类的List_display中添加 session_users 方法,
这将使用Sessionuser型号Admin的过滤数据重定向。
Make
username
model field unique inUser
model.and Add a session_users method in list_display of UserAdmin class
This will redirect with filtered data of SessionUser model-admin.
我认为抛弃外键不是一个好主意,因为应该添加某些用户名相似的机会,
unique = true
条件。i think leaving out the foreign key is not a good idea since there are chances of some usernames to be similar to avoid that,
unique=True
condition should be added.