2006年04月08日 星期六 15:42
在db-api中有这样一段例子: models: class Poll(meta.Model): slug = meta.SlugField(unique_for_month='pub_date') question = meta.CharField(maxlength=255) pub_date = meta.DateTimeField() expire_date = meta.DateTimeField() def __repr__(self): return self.question class Choice(meta.Model): poll = meta.ForeignKey(Poll, edit_inline=meta.TABULAR, num_in_admin=10, min_num_in_admin=5) choice = meta.CharField(maxlength=255, core=True) votes = meta.IntegerField(editable=False, default=0) def __repr__(self): return self.choice 在交互下有这样一段: >>> from datetime import datetime >>> p1 = polls.Poll(slug='whatsup', question="What's up?", ... pub_date=datetime(2005, 2, 20), expire_date=datetime(2005, 3, 20)) >>> p1.save() >>> p2 = polls.Poll(slug='name', question="What's your name?", ... pub_date=datetime(2005, 3, 20), expire_date=datetime(2005, 4, 20)) >>> p2.save() >>> polls.get_list() [What's up?, What's your name?] >>> polls.get_values() [{'id': 1, 'slug': 'whatsup', 'question': "What's up?", 'pub_date': datetime.datetime(2005, 2, 20), 'expire_date': datetime.datetime(2005, 3, 20)}, {'id': 2, 'slug': 'name', 'question': "What's your name?", 'pub_date': datetime.datetime(2005, 3, 20), 'expire_date': datetime.datetime(2005, 4, 20)}] >>> polls.get_values(fields=['id', 'slug']) [{'id': 1, 'slug': 'whatsup'}, {'id': 2, 'slug': 'name'}] 这里有个polls.get_list() 这个polls是什么呢?models的名字?models通常文件名就是models吧? 那么是大类? 例如: class polls(....): class ..... 这样? 我测试了 也不对啊 它是什么呢? 谢谢 -------------- next part -------------- An HTML attachment was scrubbed... URL: http://lists.exoweb.net/pipermail/python-chinese/attachments/20060408/86cb5d73/attachment.html
Zeuux © 2025
京ICP备05028076号