I have a model named cms_user which has an auth_user id as foreign key. So I want to iterate through cms_user model using request.user.
cms_user model:
from __future__ import unicode_literals
from django.db import models
from django.contrib.auth.models import User
from cms.models.masterCmsUserTypes import MasterCmsUserTypes
class CmsUser(models.Model):
userId = models.ForeignKey(User,db_column='userId')
userTypeId = models.ForeignKey(MasterCmsUserTypes,db_column='userTypeId')
status = models.BooleanField(db_column="status", default=False, help_text="")
isDelete = models.BooleanField(db_column="isDelete", default=False, help_text="")
createdAt = models.DateTimeField(db_column='createdAt', auto_now=True, help_text="")
modifiedAt = models.DateTimeField(db_column='modifiedAt', auto_now=True, help_text="")
idv2 = models.IntegerField(db_column='idV2')
class Meta:
managed = False
db_table = 'cms_user'
I want to iterate to cms_user using request.user
If you want to access the CmsUser
object related to the request.user
object, there are 2 ways:
CmsUser.objects.get(user=request.user)
or
request.user.cmsuser_set.get()
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.