search

Home  >  Q&A  >  body text

Django queries database

class User(models.Model):

username = models.Charfield()


class Topic(models.Model):

# Posted by

user = models.ForeignKey(User)


class Reply(models.Model):

topic = models.ForeignKey(Topic)

# Respondent

user = models.ForeignKey(User)



Now we need to query all the replies to posts posted by a user

user = User.objects.get(pk=5)

replies = Reply. objects.filter(topic.user.id==user.id)

Always reports an error:

SyntaxError: keyword can't be an expression

May I ask? How to deal with it so that you can get all the replies.

欢乐时光马上就要开始了欢乐时光马上就要开始了1929 days ago1138

reply all(1)I'll reply

  • 殘留の回憶

    殘留の回憶2019-08-21 09:35:22

    I’m not familiar with django, so I can’t help you. I broke 0 replies,~~

    reply
    0
  • Cancelreply