1

I am using django with postgreSQL to make a book library website. I have three models below, they were all simplified for the showcase:

class Tag(models.Model):
 TagName = models.CharField(verbose_name='Tag name',max_length=128)

class Author(models.Model):
 AuthorName = models.CharField(verbose_name='Author name',max_length=128)

class Book(models.Model):
 BookName = models.CharField(verbose_name='Book name',max_length=128)
 TagName = models.ForeignKey(Tag, on_delete=models.CASCADE, verbose_name='Tag Name')
 AuthorName = models.ForeignKey(Author, on_delete=models.CASCADE, verbose_name='Author Name')

Now with data ready and connected with each other, I was trying to use the postgreSQL Schema Views to make a booklist, which I wanted to be shown like this:

SEARCHVIEW
/TagName    /AuthorName    /BookName                   
Recipes     Jeff           Chef Jeff's food  
Recipes     Jeff           Foods in Europe  
Stories     Jeff           an Adventure Story 

I was trying to use the PostgreSQL's query tool to generate the views for me, but I found a hard time trying that, even though I did a lot of research it still got something wrong.

May I ask for my instance above, how can I create this view by using the query tool of PostgreSQL? Thank you!

lepsch
  • 8,927
  • 5
  • 24
  • 44
deeded307
  • 29
  • 4
  • 1
    Would this help? https://www.postgresql.org/docs/current/tutorial-views.html – richyen Sep 13 '22 at 22:35
  • thank you for revising the question and providing some reference for me, and sorry for my terrible grammar! Actually I have already checked most of the online documents and examples about SQL views ... guess I will keep trying. – deeded307 Sep 14 '22 at 18:10

0 Answers0