开发者

How to check which user has added selected post?

I would like to know which user has added selected post. For example I have:

post = Posts.objects.all()[0]

this i开发者_如何学Pythons my selected post and how can I get infos about the user which added the post?

Best regards, nykon

PS. the model:

class Post(models.Model):
     number = models.IntegerField(verbose_name = u'Number')

Users have access to add number, so I have got a collection of numbers. I would like to know which user added given number.


You'll need to add a field that stores the user to your Post model. Something like:

class Post(models.Model):
  number = models.IntegerField('Number')
  user = models.ForeignKey(User)

Otherwise this information will not be available to you.


If you don't have a field that stores the user, and set it when the record is created, you can't do this.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜