2007年04月23日 星期一 03:53
ΪʲôÔÚÄ£°åÖÐÊÇʹÓÃ{{for p in products.productimages_set.all}}·½·¨·ÃÎʶÔÏóµÄ¼¯ºÏ?
ÉÏÃæµÄallûÓÐÀ¨ºÅ,¾ÍÊÇ˵²»ÊÇ·½·¨?ÊÇÊôÐÔ?
ÄÇÎÒÒª·ÃÎʵÚÒ»¸ö¶ÔÏó,»òÕßÊÇlatest¶ÔÏóʱ,¸ÃÈçºÎ×ö?
ÎÒÔÚ´úÂëÖÐд{{product.productimages_set.latest('id')}}»òÕß{{product.productimages_set.all[0].name}}Ö®ÀàµÄ×ÜÊdzö´í!
-------------- 下一部分 --------------
Ò»¸öHTML¸½¼þ±»ÒƳý...
URL: http://python.cn/pipermail/python-chinese/attachments/20070423/48f4da80/attachment.htm
2007年04月23日 星期一 04:30
ÔõÑù²ì¿´ reST ¸ñʽÎı¾ µÄÎı¾ÄØ£¿ÎÒ°ÑdjangoµÄdoc svnÏÂÀ´ÁË£¬²»¹ý¿´ÆðÀ´ÓеãÂÒ£¬ÎÄ×ÖûÓиñʽ£¬ÔõÑù²ì¿´ reST ¸ñʽÎı¾ µÄÎı¾ÄØ£¿ -------------- 下一部分 -------------- Ò»¸öHTML¸½¼þ±»ÒƳý... URL: http://python.cn/pipermail/python-chinese/attachments/20070423/f7ca1e66/attachment.html
2007年04月23日 星期一 09:39
*
>
> 为什么在模板中是使用{{for p in products.productimages_set.all}}方法访问对象的集合?
> 上面的all没有括号,就是说不是方法?是属性?
>
*
是个方法,django 模板会自动调用的。
*
>
> 那我要访问第一个对象,或者是latest对象时,该如何做?
> 我在代码中写{{product.productimages_set.latest('id')}}或者{{
> product.productimages_set.all[0].name}}之类的总是出错!
>
*
那么你需要在 views 中定义这些属性 product.lastest_image = product.productimages_set.all
[0]
然后在模板中使用 product.lastest_image.name 等等。
> 怎样察看 reST 格式文本 的文本呢?我把django的doc svn下来了,不过看起来有点乱,文字没有格式,怎样察看 reST 格式文本
> 的文本呢?
转成html再看,先安装 docutils ,里面 tools 文件夹中有个 buildhtml.py 到文档目录下运行一下就OK了。
--
http://codeplayer.blogspot.com/
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://python.cn/pipermail/python-chinese/attachments/20070423/af360a79/attachment.htm
2007年04月23日 星期一 09:40
*
>
> 那我要访问第一个对象,或者是latest对象时,该如何做?
> > > 我在代码中写{{product.productimages_set.latest('id')}}或者{{
> > > product.productimages_set.all[0].name}}之类的总是出错!
> > >
> >
> > 那么你需要在 views 中定义这些属性 product.lastest_image =
> > product.productimages_set.all[0]
> > 然后在模板中使用 product.lastest_image.name 等等。
> >
> *
>
其实这个属性挺适合在 model 中定义的。
@property
def lastest_image(self):
return self.productimages_set.all[0]
--
http://codeplayer.blogspot.com/
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://python.cn/pipermail/python-chinese/attachments/20070423/cafdeb01/attachment.html
2007年04月23日 星期一 11:32
class Product(models.Model):
name = models.CharField(maxlength = 64)
class ProductImages(models.Model):
product = models.ForeignKey(Product);
thumb_path = models.ImagePath(upload_to = 'product');
ÏÖÔÚÈç¹ûÒªÔÚÒ»¸ölist.htmlÁгöËùÓвúÆ·,ºÍ´Ë²úÆ·µÄµÚÒ»¸öthumbnail ¸÷λÊÇÈçºÎ×öµÄ?
Ŀǰ,ÎÒÊÇÕâÑù×ö,µ«²»Ã÷°×,ÈçºÎ»ñµÃµÚÒ»¸öËõÂÔÍ¼ÄØ?
{% for pro in products %}
{# pro.productimages_set.all[0].thumb_path ´íÎó,²»ÖªÈçºÎ»ñµÃµÚÒ»¸ö#}
{# pro.productimages_set.latest('id').thumb_path ´íÎó,²»ÖªÈçºÎ»ñµÃµÚÒ»¸ö#}
{# pro.get_productimages_list[0].thumb_path ³ö´í#}
{% for pic in pro.productimages_set.all %}
{% endfor %}
{% endfor %}
Òªµ¥¶À¶¨Òå get_lastproductimage·½·¨À´»ñµÃͼƬ?
bbenyu
2007-04-23
·¢¼þÈË£º »ÆÒã
·¢ËÍʱ¼ä£º 2007-04-23 09:40:59
ÊÕ¼þÈË£º python-chinese在lists.python.cn
³ËÍ£º
Ö÷Ì⣺ Re: [python-chinese]Çë½Ì,DjangoÄ£°åÖзÃÎÊinstace.relatedobject_set·½·¨ÎÊÌâ.
ΪʲôÔÚÄ£°åÖÐÊÇʹÓÃ{{for p in products.productimages_set.all}}·½·¨·ÃÎʶÔÏóµÄ¼¯ºÏ?
ÉÏÃæµÄallûÓÐÀ¨ºÅ,¾ÍÊÇ˵²»ÊÇ·½·¨?ÊÇÊôÐÔ?
ÊǸö·½·¨£¬django Ä£°å»á×Ô¶¯µ÷Óõġ£
ÄÇÎÒÒª·ÃÎʵÚÒ»¸ö¶ÔÏó,»òÕßÊÇlatest¶ÔÏóʱ,¸ÃÈçºÎ×ö?
ÎÒÔÚ´úÂëÖÐд{{product.productimages_set.latest('id')}}»òÕß{{product.productimages_set.all[0].name}}Ö®ÀàµÄ×ÜÊdzö´í!
ÄÇôÄãÐèÒªÔÚ views Öж¨ÒåÕâЩÊôÐÔ product.lastest_image = product.productimages_set.all[0]
È»ºóÔÚÄ£°åÖÐʹÓà product.lastest_image.name µÈµÈ¡£
ÔõÑù²ì¿´ reST ¸ñʽÎı¾ µÄÎı¾ÄØ£¿ÎÒ°ÑdjangoµÄdoc svnÏÂÀ´ÁË£¬²»¹ý¿´ÆðÀ´ÓеãÂÒ£¬ÎÄ×ÖûÓиñʽ£¬ÔõÑù²ì¿´ reST ¸ñʽÎı¾ µÄÎı¾ÄØ£¿
ת³ÉhtmlÔÙ¿´£¬ÏȰ²×° docutils £¬ÀïÃæ tools Îļþ¼ÐÖÐÓиö buildhtml.py µ½ÎĵµÄ¿Â¼ÏÂÔËÐÐһϾÍOKÁË¡£
--
http://codeplayer.blogspot.com/
-------------- 下一部分 --------------
Ò»¸öHTML¸½¼þ±»ÒƳý...
URL: http://python.cn/pipermail/python-chinese/attachments/20070423/1c1b6ae6/attachment.html
2007年04月23日 星期一 11:36
项目需要在emule的基础上改,C++太复杂了, 有python版的就好了, 谁有相关的信息,谢谢! _______________________________________________ python-chinese Post: send python-chinese在lists.python.cn Subscribe: send subscribe to python-chinese-request在lists.python.cn Unsubscribe: send unsubscribe to python-chinese-request在lists.python.cn Detail Info: http://python.cn/mailman/listinfo/python-chinese
2007年04月23日 星期一 11:39
ÄãÓÐÌý˵ij¸öÖøÃûµÄBTÈí¼þ¾ÍÊÇÓÃPYдµÄ ÄãÏëÔÙÔìÒ»¸öÂÖ×Ó£¿ On 4/23/07, shaying <shaying在software.ict.ac.cn> wrote: > > ÏîÄ¿ÐèÒªÔÚemuleµÄ»ù´¡Éϸģ¬C++Ì«¸´ÔÓÁË£¬ > ÓÐpython°æµÄ¾ÍºÃÁË£¬ > ËÓÐÏà¹ØµÄÐÅÏ¢£¬Ð»Ð»£¡ > > _______________________________________________ > python-chinese > Post: send python-chinese在lists.python.cn > Subscribe: send subscribe to python-chinese-request在lists.python.cn > Unsubscribe: send unsubscribe to python-chinese-request在lists.python.cn > Detail Info: http://python.cn/mailman/listinfo/python-chinese > _______________________________________________ > python-chinese > Post: send python-chinese在lists.python.cn > Subscribe: send subscribe to python-chinese-request在lists.python.cn > Unsubscribe: send unsubscribe to python-chinese-request在lists.python.cn > Detail Info: http://python.cn/mailman/listinfo/python-chinese -- ÎÒ×ßµ½Ò»¸öİÉúµÄµØ·½ ¸æËß±ðÈË ÎÒҪȥÁ÷ÀË Å¶£¬ÎÒҪȥÁÆÉË¡¡ ÓòÃû¹ýÆÚÁË¡£ -------------- 下一部分 -------------- Ò»¸öHTML¸½¼þ±»ÒƳý... URL: http://python.cn/pipermail/python-chinese/attachments/20070423/022784a3/attachment.htm
2007年04月23日 星期一 11:50
On 4/23/07, 大郎 <iexper在gmail.com> wrote: > 你有听说某个著名的BT软件就是用PY写的 Bt 和 eMule 使用的 eDonkey2k 协议不同的; > 你想再造一个轮子? > > > On 4/23/07, shaying <shaying在software.ict.ac.cn> wrote: > > 项目需要在emule的基础上改,C++太复杂了, > > 有python版的就好了, > > 谁有相关的信息,谢谢! > > > > _______________________________________________ > > python-chinese > > Post: send python-chinese在lists.python.cn > > Subscribe: send subscribe to > python-chinese-request在lists.python.cn > > Unsubscribe: send unsubscribe to > python-chinese-request在lists.python.cn > > Detail Info: > http://python.cn/mailman/listinfo/python-chinese > > _______________________________________________ > > python-chinese > > Post: send python-chinese在lists.python.cn > > Subscribe: send subscribe to > python-chinese-request在lists.python.cn > > Unsubscribe: send unsubscribe to > python-chinese-request在lists.python.cn > > Detail Info: > http://python.cn/mailman/listinfo/python-chinese > > > > -- > 我走到一个陌生的地方 > 告诉别人 我要去流浪 > 哦,我要去疗伤…… > > 域名过期了。 > _______________________________________________ > python-chinese > Post: send python-chinese在lists.python.cn > Subscribe: send subscribe to > python-chinese-request在lists.python.cn > Unsubscribe: send unsubscribe to > python-chinese-request在lists.python.cn > Detail Info: > http://python.cn/mailman/listinfo/python-chinese > -- '''Time is unimportant, only life important! http://zoomquiet.org blog在http://blog.zoomquiet.org/pyblosxom/ wiki在http://wiki.woodpecker.org.cn/moin/ZoomQuiet scrap在http://floss.zoomquiet.org douban在http://www.douban.com/people/zoomq/ ____________________________________ Pls. use OpenOffice.org to replace M$ Office. http://zh.openoffice.org Pls. use 7-zip to replace WinRAR/WinZip. http://7-zip.org/zh-cn/ You can get the truely Freedom 4 software. '''
2007年04月23日 星期一 11:58
>
> class Product(models.Model):
> name = models.CharField(maxlength = 64)
>
> class ProductImages(models.Model):
> product = models.ForeignKey(Product);
> thumb_path = models.ImagePath(upload_to = 'product');
>
> 现在如果要在一个list.html列出所有产品,和此产品的第一个thumbnail 各位是如何做的?
> 目前,我是这样做,但不明白,如何获得第一个缩略图呢?
> {% for pro in products %}
> {# pro.productimages_set.all[0].thumb_path 错误,不知如何获得第一个#}
> {# pro.productimages_set.latest('id').thumb_path 错误,不知如何获得第一个#}
> {# pro.get_productimages_list[0].thumb_path 出错#}
> {% for pic in pro.productimages_set.all %}
>
> {% endfor %}
> {% endfor %}
>
> 要单独定义 get_lastproductimage方法来获得图片?
>
models:
class Product(models.Model):
...
@property
def first_image(self):
return self.productimage_set.latest('id')
模板:
{% for pro in products %}
{{pro.first_image.thumb_path}}
...
{% endfor %}
--
http://codeplayer.blogspot.com/
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://python.cn/pipermail/python-chinese/attachments/20070423/91bf1d52/attachment.html
Zeuux © 2025
京ICP备05028076号