开发者

How to make custom join query with Django?

I have these 2 models:

genre = (
    ('D', 'Dramatic'),
    ('T', 'Thriller'),
    ('L', 'Love'),
)

class Book(models.Model):


    title = models.C开发者_StackOverflow社区harField(max_length=100)
    genre = models.CharField(max_length=1, choices=genre)


class Author(models.Model):

    user = models.ForeignKey(User, unique=True)
    born = models.DateTimeField('born')    
    book = models.ForeignKey(Book)

I need to retrieve first_name and last_name of all authors of dramatic's books.

How can I do this in django ?


Like the documentation says...

Author.objects.filter(book__genre='D')
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜