Django_ORMデータテーブルクエリーのまとめ
3607 ワード
class Author(models.Model):
''' '''
name = models.CharField(max_length=32)
book = models.ManyToManyField(to="Book")
# def __str__(self):
# return self.name
class Book(models.Model):
''' '''
title = models.CharField(max_length=32)
price = models.CharField(max_length=32)
publish = models.ForeignKey(to="Publish")
# def __str__(self):
# return self.title
#egon
class Publish(models.Model):
''' '''
address = models.CharField(max_length=32)
# def __str__(self):
# return self.address
# author = models.Author.objects.all() # queryset author book
# book = models.Book.objects.all() # queryset book publish
# publish = models.Publish.objects.all() # queryset
# #================================================ ============================================================
# for te in author:
# print("======author",te.name) #
# print("======author_book",te.book.first().title) #
# print("======author_book_publish",te.book.first().publish.address) # ,
# for te in book:
# print("========tetetet",te)
# print("======book",te.title,te.price) #
# print("========book_publish",te.publish.address) #
# print("==========book_author",te.author_set.first()) #
# for te in publish:
# print("=====publish",te.address) #
# print("=====publish_book",te.book_set.first().title)
# print("=======publish_book_author",te.book_set.first().author_set.first())
#
#
# author_book_publish = author.first().book.all().first().title
# print("==================================",author_book_publish)
# #============================================ ===========================================================
# author = models.Author.objects.all() # queryset author book
# book = models.Book.objects.all() # queryset book publish
# publish = models.Publish.objects.all() # queryset
# book_title = author.filter(name="egon").values("book__title") # author book title
# book_price = author.filter(name="egon").values("book__price") # author book price
# book_publish_address = author.filter(name="egon").values("book__publish__address") # author
# print("============book_title|book_price",book_title,book_price)
# print("============book_publish_addredd",book_publish_address)
# #============================================ ===========================================================
# book_title = publish.filter(address=" ").values("book__title")
# book_price = publish.filter(address=" ").values("book__price")
# publish_book = publish.filter(address=" ").values("book__author")
# publish_author_book = publish.filter(address=" ").values("book__author__name")
# print("============book_title|book_price",book_title,book_price)
# print("============publish_book",publish_book)
# print("============publish_author_book",publish_author_book)
########################################################################################################################