Python论坛  - 讨论区

标题:[python-chinese] django文档学习疑问

2006年04月08日 星期六 15:42

风向标 vaneoooo at gmail.com
Sat Apr 8 15:42:40 HKT 2006

在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

[导入自Mailman归档:http://www.zeuux.org/pipermail/zeuux-python]

如下红色区域有误,请重新填写。

    你的回复:

    请 登录 后回复。还没有在Zeuux哲思注册吗?现在 注册 !

    Zeuux © 2025

    京ICP备05028076号