相关的对象-libmodbus源码解析

时间:2024-07-14 01:47:21
【文件属性】:

文件名称:相关的对象-libmodbus源码解析

文件大小:7.37MB

文件格式:PDF

更新时间:2024-07-14 01:47:21

PDF

9.1相关的对象 我们在第 4 章定义了下面几个模型: from django.db import models class Publisher(models.Model): name = models.CharField(max_length=30) address = models.CharField(max_length=50) city = models.CharField(max_length=60) state_province = models.CharField(max_length=30) country = models.CharField(max_length=50) website = models.URLField() def __str__(self): return self.name class Author(models.Model): first_name = models.CharField(max_length=30) last_name = models.CharField(max_length=40) email = models.EmailField() def __str__(self): return '%s %s' % (self.first_name, self.last_name) class Book(models.Model): title = models.CharField(max_length=100) authors = models.ManyToManyField(Author) publisher = models.ForeignKey(Publisher) publication_date = models.DateField() def __str__(self): return self.title 我们知道,访问数据库中某一列很简单,只需访问对象的属性。例如,若想查看 ID 为 50 的图书的书名,可 以这么做: >>> from mysite.books.models import Book >>> b = Book.objects.get(id=50) >>> b.title 'The Django Book' 137


网友评论