本文整理汇总了Python中blog.models.Category.title方法的典型用法代码示例。如果您正苦于以下问题:Python Category.title方法的具体用法?Python Category.title怎么用?Python Category.title使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类blog.models.Category
的用法示例。
在下文中一共展示了Category.title方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_create_post
# 需要导入模块: from blog.models import Category [as 别名]
# 或者: from blog.models.Category import title [as 别名]
def test_create_post(self):
# Create the post
post = Post()
category = Category(id=1)
# Set the attributes
post.title = 'My first post'
post.text = 'This is my first blog post'
post.pub_date = timezone.now()
category.title = 'My category'
post.category = category
# Save it
post.save()
# Check we can find it
all_posts = Post.objects.all()
self.assertEquals(len(all_posts), 1)
only_post = all_posts[0]
self.assertEquals(only_post, post)
# Check attributes
self.assertEquals(only_post.title, 'My first post')
self.assertEquals(only_post.text, 'This is my first blog post')
self.assertEquals(only_post.pub_date.day, post.pub_date.day)
示例2: Category
# 需要导入模块: from blog.models import Category [as 别名]
# 或者: from blog.models.Category import title [as 别名]
category.post_set.all() # [Post]
tag.post_set.all() # [Post]
# Начало другого урока
from blog.models import Category, Post
# Создание
c = Category(title='Perl')
c.save()
# За один вызов
c = Category.objects.create(title='Python')
# create - создать экземпляр модели
# Изменение
c.title = 'About Python'
c.save()
# Создание объектов со связями
t = Tag(title='easy')
t.save()
c = Category(title='Python')
c.save()
p = Post(title='...', ... , category=c или category_id=3)
p.save()
# Многие ко многим
p.tags = Tag.objects.all()[0:3] # [ Tag ]
p.save()
p.tags.add(t)