Python论坛  - 讨论区

标题:[python-chinese] Django 中 models.py

2007年04月24日 星期二 10:52

Ben Luo benluo在gmail.com
星期二 四月 24 10:52:40 HKT 2007

ÎÒÓÐÒ»¸ömodels.py

from django.db import models

class Cities(models.Model):
    city_name_en = models.CharField(maxlength=55)
    city_name_cn = models.CharField(maxlength=55)
    state_name_en = models.CharField(maxlength=55)
    state_name_cn = models.CharField(maxlength=55)
    country_name_en = models.CharField(maxlength=55)
    country_name_cn = models.CharField(maxlength=55)


class Companies(models.Model):
    name_en = models.CharField(maxlength=55)
    name_cn = models.CharField(maxlength=55)
    address_en = models.CharField(maxlength=250)
    address_cn = models.CharField(maxlength=250)
    city = models.ForeignKey(Cities)

class Products(models.Model):
    name_en = models.CharField(maxlength=250)
    name_cn = models.CharField(maxlength=250)
    company = models.ManyToManyField(Companies)

class Prices(models.Model):
    price = models.FloatField(max_digits=10, decimal_places=3)
    product = models.ForeignKey(???????) #Ó¦¸ÃÔõô×ö£¿£¿£¿£¿

ÒòΪÿ¸ö¹«Ë¾ÓжàÖÖ²úÆ·£¬Ã¿ÖÖ²úÆ·Ò²Óжà¸ö¹«Ë¾Éú²ú£¬ËùÒÔÎÒÏëÒª Prices.product ÊÇÖ¸Ïò django ×Ô¶¯Éú³ÉµÄ manytomany
µÄÄǸö±í(products_companies), Ó¦¸ÃÔõô×ö£¿
-------------- 下一部分 --------------
Ò»¸öHTML¸½¼þ±»ÒƳý...
URL: http://python.cn/pipermail/python-chinese/attachments/20070424/cded2aca/attachment.html 

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

2007年04月24日 星期二 10:57

Tian askfor在gmail.com
星期二 四月 24 10:57:07 HKT 2007

²»ÊÇ˵²»Ö§³ÖÁªºÏÖ÷¼üµÄÍâ¼üÂð

On 4/24/07, Ben Luo <benluo在gmail.com> wrote:
>
> ÎÒÓÐÒ»¸ömodels.py
>
> from django.db import models
>
> class Cities(models.Model):
>     city_name_en = models.CharField(maxlength=55)
>     city_name_cn = models.CharField(maxlength=55)
>     state_name_en = models.CharField (maxlength=55)
>     state_name_cn = models.CharField(maxlength=55)
>     country_name_en = models.CharField(maxlength=55)
>     country_name_cn = models.CharField(maxlength=55)
>
>
> class Companies(models.Model):
>     name_en = models.CharField(maxlength=55)
>     name_cn = models.CharField(maxlength=55)
>     address_en = models.CharField(maxlength=250)
>     address_cn = models.CharField(maxlength=250)
>     city = models.ForeignKey (Cities)
>
> class Products(models.Model):
>     name_en = models.CharField(maxlength=250)
>     name_cn = models.CharField(maxlength=250)
>     company = models.ManyToManyField(Companies)
>
> class Prices(models.Model):
>     price = models.FloatField(max_digits=10, decimal_places=3)
>     product = models.ForeignKey(???????) #Ó¦¸ÃÔõô×ö£¿£¿£¿£¿
>
> ÒòΪÿ¸ö¹«Ë¾ÓжàÖÖ²úÆ·£¬Ã¿ÖÖ²úÆ·Ò²Óжà¸ö¹«Ë¾Éú²ú£¬ËùÒÔÎÒÏëÒª Prices.product ÊÇÖ¸Ïò django ×Ô¶¯Éú³ÉµÄ manytomany
> µÄÄǸö±í(products_companies), Ó¦¸ÃÔõô×ö£¿
>
> _______________________________________________
> 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/20070424/a1395bd5/attachment.htm 

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

2007年04月24日 星期二 11:52

黄毅 yi.codeplayer在gmail.com
星期二 四月 24 11:52:28 HKT 2007

On 4/24/07, Ben Luo <benluo at gmail.com> wrote:
>
> 我有一个models.py
>
> from django.db import models
>
> class Cities(models.Model):
>     city_name_en = models.CharField(maxlength=55)
>     city_name_cn = models.CharField(maxlength=55)
>     state_name_en = models.CharField (maxlength=55)
>     state_name_cn = models.CharField(maxlength=55)
>     country_name_en = models.CharField(maxlength=55)
>     country_name_cn = models.CharField(maxlength=55)
>
>
> class Companies(models.Model):
>     name_en = models.CharField(maxlength=55)
>     name_cn = models.CharField(maxlength=55)
>     address_en = models.CharField(maxlength=250)
>     address_cn = models.CharField(maxlength=250)
>     city = models.ForeignKey (Cities)
>
> class Products(models.Model):
>     name_en = models.CharField(maxlength=250)
>     name_cn = models.CharField(maxlength=250)
>     company = models.ManyToManyField(Companies)
>
> class Prices(models.Model):
>     price = models.FloatField(max_digits=10, decimal_places=3)
>     product = models.ForeignKey(???????) #应该怎么做????
>
> 因为每个公司有多种产品,每种产品也有多个公司生产,所以我想要 Prices.product 是指向 django 自动生成的 manytomany
> 的那个表(products_companies), 应该怎么做?


class Companies(models.Model):
    ...
    @property
    def products(self):
        return [assoc.product for assoc in self.associations_set.all()]

class Products(models.Model):
    ...
     @property
    def companies(self):
        return [assoc.company for assoc in self.associations_set.all()]

class Associations(models.Model):
    company = models.ForeignKey(Companies)
    product = models.ForeignKey(Products)
    price = models.FloatField(...)

我建议你使用上面这样的定义。
说实话,模型稍微复杂了一些后(比如你这个例子),django 的 orm 就不太合适了。

-- 
http://codeplayer.blogspot.com/
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://python.cn/pipermail/python-chinese/attachments/20070424/4a9a900e/attachment.htm 

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

2007年04月24日 星期二 13:12

Ben Luo benluo在gmail.com
星期二 四月 24 13:12:01 HKT 2007

On 4/24/07, »ÆÒã <yi.codeplayer在gmail.com> wrote:
>
>
> class Companies(models.Model):
>     ...
>     @property
>     def products(self):
>         return [assoc.product for assoc in self.associations_set.all()]
>
> class Products(models.Model):
>     ...
>      @property
>     def companies(self):
>         return [assoc.company for assoc in self.associations_set.all()]
>
> class Associations(models.Model):
>     company = models.ForeignKey(Companies)
>     product = models.ForeignKey(Products)
>     price = models.FloatField(...)
>
> ÎÒ½¨ÒéÄãʹÓÃÉÏÃæÕâÑùµÄ¶¨Òå¡£
> ˵ʵ»°£¬Ä£ÐÍÉÔ΢¸´ÔÓÁËһЩºó£¨±ÈÈçÄãÕâ¸öÀý×Ó£©£¬django µÄ orm ¾Í²»Ì«ºÏÊÊÁË¡£
>
>

·Ç³£¸Ðл¡£Èç¹ûÕâôÂé·³£¬ÎÒ»¹²»ÈçÊÖ¶¯Ð´Ò»¸ö±íËãÁË¡£È·ÊµÈçÄãËù˵£¬ËüµÄORMÌ«ÈõÁË¡£
ÎÒ¾õµÃÕâÖÖÐèÇóÔÚÒµÎñÁ÷³ÌÉÏÃæÊÇ×îÆ½³£µÄÁË¡£
-------------- 下一部分 --------------
Ò»¸öHTML¸½¼þ±»ÒƳý...
URL: http://python.cn/pipermail/python-chinese/attachments/20070424/a94492f5/attachment.html 

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

2007年04月24日 星期二 14:14

limodou limodou在gmail.com
星期二 四月 24 14:14:36 HKT 2007

Prices指向Product和Company不行吗?按理说直接指向Product就可以了,但如果想直接通过Company得到Prices就可以通过Prices指向Company,这是为了访问方便的缘故。

-- 
I like python!
UliPad <>: http://wiki.woodpecker.org.cn/moin/UliPad
My Blog: http://www.donews.net/limodou

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

2007年04月24日 星期二 14:19

Tian askfor在gmail.com
星期二 四月 24 14:19:38 HKT 2007

PricesÖ¸ÏòProductºÍCompany²»ÐÐÂð£¿
productA ºÍ companyA ÓйØÁª
productB ºÍ companyB ÓйØÁª
pricesÖ¸ÏòProduct company²»Äܱ£Ö¤²»³öÏÖproductAºÍcompanyBµÄ¼Ç¼¡£

ͬһ¸öproductÔÚ¶à¸öcomanyÓв»Í¬µÄ¼Û¸ñ  Ö±½ÓÖ¸Ïòproduct±ä³ÉÒ»¸öproductÒ»¸öpriceÁË


On 4/24/07, limodou <limodou在gmail.com> wrote:
>
>
> PricesÖ¸ÏòProductºÍCompany²»ÐÐÂ𣿰´Àí˵ֱ½ÓÖ¸ÏòProduct¾Í¿ÉÒÔÁË£¬µ«Èç¹ûÏëÖ±½Óͨ¹ýCompanyµÃµ½Prices¾Í¿ÉÒÔͨ¹ýPricesÖ¸ÏòCompany£¬ÕâÊÇΪÁË·ÃÎÊ·½±ãµÄÔµ¹Ê¡£
>
> --
> I like python!
> UliPad <>: http://wiki.woodpecker.org.cn/moin/UliPad
> My Blog: http://www.donews.net/limodou
> _______________________________________________
> 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/20070424/7833f480/attachment.htm 

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

2007年04月27日 星期五 08:59

Rodin schludern在gmail.com
星期五 四月 27 08:59:43 HKT 2007

                              + Product
ProductWithPrice<---|
                              + Company

ÕâÑù¶à·ÖÒ»¸ö±í³öÀ´
-------------- 下一部分 --------------
Ò»¸öHTML¸½¼þ±»ÒƳý...
URL: http://python.cn/pipermail/python-chinese/attachments/20070427/ddf6fd5d/attachment-0001.html 

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

2007年04月27日 星期五 13:58

mvfirst mvfirst在126.com
星期五 四月 27 13:58:22 HKT 2007

ÎÒÊÔͼ´ÓÒ»¸öÊý¾Ý¿â±íÖжÁȡһ¸ö×ֶΣ¨¸Ã×Ö¶ÎÄÚÈÝΪÖÐÎÄ£©£¬ÔÚ°ÑÕâ¸öÖÐÎĸ³Öµ¸øÒ»¸ö×Ö·û´®±äÁ¿Ê±£¬³ö´í£º
UnicodeDecodeError
Exception Value:'ascii' codec can't decode byte 0xe7 in position 0: ordinal not in range(128)

¨‹ Local vars 
VariableValue
objÓ¯ÀûÀà


´úÂëÈçÏ£º
  str_zhichu = ""
  cx = sqlite.connect("data.db")
  cu = cx.cursor()
  cu.execute("select JobTimeAttr from address_basedict")
  for row in cu.fetchall():
     str_zhichu = str_zhichu + row[0]   ££³ö´í




mvfirst
2007-04-27



·¢¼þÈË£º Rodin
·¢ËÍʱ¼ä£º 2007-04-27 09:00:13
ÊÕ¼þÈË£º python-chinese在lists.python.cn
³­ËÍ£º 
Ö÷Ì⣺ Re: [python-chinese]Django ÖÐ models.py

                              + Product 
ProductWithPrice<---|            
                              + Company 

ÕâÑù¶à·ÖÒ»¸ö±í³öÀ´
-------------- 下一部分 --------------
Ò»¸öHTML¸½¼þ±»ÒƳý...
URL: http://python.cn/pipermail/python-chinese/attachments/20070427/0f54ab92/attachment.htm 

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

2007年04月27日 星期五 14:11

limodou limodou在gmail.com
星期五 四月 27 14:11:46 HKT 2007

On 4/27/07, mvfirst <mvfirst在126.com> wrote:
>
>  ÎÒÊÔͼ´ÓÒ»¸öÊý¾Ý¿â±íÖжÁȡһ¸ö×ֶΣ¨¸Ã×Ö¶ÎÄÚÈÝΪÖÐÎÄ£©£¬ÔÚ°ÑÕâ¸öÖÐÎĸ³Öµ¸øÒ»¸ö×Ö·û´®±äÁ¿Ê±£¬³ö´í£º
>   UnicodeDecodeError Exception Value: 'ascii' codec can't decode byte 0xe7
> in position 0: ordinal not in range(128)
>  ¨‹ Local vars <http://127.0.0.1:8000/address/personweekreport/#>
>   Variable Value  obj Ó¯ÀûÀà
>
> ´úÂëÈçÏ£º
>   str_zhichu = ""
>   cx = sqlite.connect("data.db")
>   cu = cx.cursor()
>   cu.execute("select JobTimeAttr from address_basedict")
>   for row in cu.fetchall():
>      str_zhichu = str_zhichu + row[0]   ££³ö´í
>
>  ------------------------------
>
ʲôÊý¾Ý¿â£¬½¨Òé¼ÓЩµ÷ÊÔÐÅÏ¢¿´Ò»Ï¡£Èç´òÓ¡row[0]µÄÀàÐÍ¡£µ±Ò»¸östrÓëÒ»¸öunicodeÏà¼Óʱstr»á×Ô¶¯×ªÎªunicode,Ëü»áʹÓÃϵͳȱʡencoding½øÐÐת»»£¬Òò´ËÔÚÓÐÖÐÎÄʱ¿ÉÄܳö´í¡£×îºÃÖ÷¶¯½«·ÇunicodeתΪunicodeÔÙÏà¼Ó¡£

-- 
I like python!
UliPad <>: http://wiki.woodpecker.org.cn/moin/UliPad
My Blog: http://www.donews.net/limodou
-------------- 下一部分 --------------
Ò»¸öHTML¸½¼þ±»ÒƳý...
URL: http://python.cn/pipermail/python-chinese/attachments/20070427/ca1b3de2/attachment.htm 

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

2007年04月27日 星期五 14:31

黄毅 yi.codeplayer在gmail.com
星期五 四月 27 14:31:30 HKT 2007

>
> 我试图从一个数据库表中读取一个字段(该字段内容为中文),在把这个中文赋值给一个字符串变量时,出错:
>   UnicodeDecodeError Exception Value: 'ascii' codec can't decode byte 0xe7
> in position 0: ordinal not in range(128)
> ▼ Local vars <http://127.0.0.1:8000/address/personweekreport/#>
>   Variable Value  obj 盈利类
>
> 代码如下:
>   str_zhichu = ""
>   cx = sqlite.connect("data.db")
>   cu = cx.cursor()
>   cu.execute("select JobTimeAttr from address_basedict")
>   for row in cu.fetchall():
>      str_zhichu = str_zhichu + row[0]   #出错
>

row[0] 其实是 unicode 对象,就像 limodou 说的,普通字符串str_zhichu会自动解码成unicode,应该是这个时候出的错,把
str_zhichu = "" 变成 str_zhichu = u"" 应该就 ok 。

另外你这代码写得可不地道,最后两句循环这样写性能会更好:
str_zhichu = u''.join(row[0] for row in cu.fetchall())

-- 
http://codeplayer.blogspot.com/
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://python.cn/pipermail/python-chinese/attachments/20070427/ef4f69b5/attachment.html 

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

2007年04月27日 星期五 14:42

Dreamingk(天成) dreamingk在gmail.com
星期五 四月 27 14:42:24 HKT 2007

最不地道的是这句
str_zhichu = u''.join(row[0] for row in cu.fetchall())

最好别用fetchall(),可以直接把cursor作为iter来用。这样写
str_zhichu = u''.join(row[0] for row in cu)

On 4/27/07, 黄毅 <yi.codeplayer在gmail.com> wrote:
>
> 我试图从一个数据库表中读取一个字段(该字段内容为中文),在把这个中文赋值给一个字符串变量时,出错:
> >   UnicodeDecodeError Exception Value: 'ascii' codec can't decode byte
> > 0xe7 in position 0: ordinal not in range(128)
> > ▼ Local vars <http://127.0.0.1:8000/address/personweekreport/#>
> >   Variable Value  obj 盈利类
> >
> > 代码如下:
> >   str_zhichu = ""
> >   cx = sqlite.connect("data.db")
> >   cu = cx.cursor()
> >   cu.execute("select JobTimeAttr from address_basedict")
> >   for row in cu.fetchall():
> >      str_zhichu = str_zhichu + row[0]   #出错
> >
>
> row[0] 其实是 unicode 对象,就像 limodou 说的,普通字符串str_zhichu会自动解码成unicode,应该是这个时候出的错,把
> str_zhichu = "" 变成 str_zhichu = u"" 应该就 ok 。
>
> 另外你这代码写得可不地道,最后两句循环这样写性能会更好:
> str_zhichu = u''.join(row[0] for row in cu.fetchall())
>
> --
> http://codeplayer.blogspot.com/
> _______________________________________________
> 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
>



-- 
Dreamingk (tc, 天成)
    dreamingk(at)gmail.com
    http://python.cn
Exoweb (北京轩辕互动科技有限公司)
Python, I love this language.
-------------- 下一部分 --------------
一个HTML附件被移除...
URL: http://python.cn/pipermail/python-chinese/attachments/20070427/71736d11/attachment.htm 

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

2007年04月27日 星期五 16:21

mvfirst mvfirst在126.com
星期五 四月 27 16:21:53 HKT 2007

ÎÒÊÇsqliteÊý¾Ý¿â£¬ÎÒÓÃdjango·â×°µÄsql²éѯ¾ÍûÓÐÕâ¸öÖÐÎÄÎÊÌ⣬Òѽâ¾ö¡£
¶àл´ó¼Ò£¡




mvfirst
2007-04-27



·¢¼þÈË£º limodou
·¢ËÍʱ¼ä£º 2007-04-27 14:12:01
ÊÕ¼þÈË£º python-chinese在lists.python.cn
³­ËÍ£º 
Ö÷Ì⣺ Re: [python-chinese]djangoÖÐÎĸ³ÖµÎÊÌâÇóÖú£¡




On 4/27/07, mvfirst <mvfirst在126.com> wrote:
ÎÒÊÔͼ´ÓÒ»¸öÊý¾Ý¿â±íÖжÁȡһ¸ö×ֶΣ¨¸Ã×Ö¶ÎÄÚÈÝΪÖÐÎÄ£©£¬ÔÚ°ÑÕâ¸öÖÐÎĸ³Öµ¸øÒ»¸ö×Ö·û´®±äÁ¿Ê±£¬³ö´í£º
UnicodeDecodeError
Exception Value:'ascii' codec can't decode byte 0xe7 in position 0: ordinal not in range(128)

¨‹ Local vars 
VariableValue
objÓ¯ÀûÀà


´úÂëÈçÏ£º
  str_zhichu = ""
  cx = sqlite.connect("data.db")
  cu = cx.cursor()
  cu.execute("select JobTimeAttr from address_basedict")
  for row in cu.fetchall():
     str_zhichu = str_zhichu + row[0]   ££³ö´í




ʲôÊý¾Ý¿â£¬½¨Òé¼ÓЩµ÷ÊÔÐÅÏ¢¿´Ò»Ï¡£Èç´òÓ¡row[0]µÄÀàÐÍ¡£µ±Ò»¸östrÓëÒ»¸öunicodeÏà¼Óʱstr»á×Ô¶¯×ªÎªunicode,Ëü»áʹÓÃϵͳȱʡencoding½øÐÐת»»£¬Òò´ËÔÚÓÐÖÐÎÄʱ¿ÉÄܳö´í¡£×îºÃÖ÷¶¯½«·ÇunicodeתΪunicodeÔÙÏà¼Ó¡£

-- 
I like python! 
UliPad <>: http://wiki.woodpecker.org.cn/moin/UliPad
My Blog: http://www.donews.net/limodou 
-------------- 下一部分 --------------
Ò»¸öHTML¸½¼þ±»ÒƳý...
URL: http://python.cn/pipermail/python-chinese/attachments/20070427/b731a113/attachment.html 

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

2007年04月27日 星期五 23:04

大郎 iexper在gmail.com
星期五 四月 27 23:04:57 HKT 2007

¼ÈÈ»Êý¾Ý¿âÀïÿ¸ö±í¶¼ÊÇÎÒÃÇ¿ÉÔ¤¼ûºÍ¿É¼ûµÄ£¬ÄÇôÇëÔÚmodels.pyÀï¾Í¿ÉÒÔ¶¨Òå³öÀ´£¬ÊÔÊÔ¿´¡£

On 4/27/07, Rodin <schludern在gmail.com> wrote:
>
>                               + Product
> ProductWithPrice<---|
>                               + Company
>
> ÕâÑù¶à·ÖÒ»¸ö±í³öÀ´
>
> _______________________________________________
> 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/20070427/94d519ce/attachment.htm 

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

2007年04月28日 星期六 04:20

bbenyu bbenyu在gmail.com
星期六 四月 28 04:20:02 HKT 2007

Çë½Ì´ó¼ÒÒ»¸öÎÊÌâ:
ÔÚÒ»°ãÇé¿öÏÂ,Èç¹ûÓжþ¸öÀà,¼ÙÉèproduct,Ò»¸ö²úÆ·¾ßÓжàÕÅͼƬ,ÄÇôÎÒĿǰÊÇ´´½¨ÁËÒ»¸öÎöµÄÄ£ÐÍproductImages²¢ÇÒ,ÔÚproductimagesÖÐÓÐ×Ö¶Î product = models.ForeignKey(Product),²»ÖªµÀÕâÑù×öÊÇ·ñ±È½ÏºÃ?
ÁíÍâ,Èç¹ûÕâÑù×öÁË,django×Ô´øµÄºǫ́¹ÜÀí,ÊÇÒÀ¾Ý²»Í¬µÄmodel½øÐд´½¨µÄ,ÄÇôÔÚÌí¼ÓÒ»¸öproductʱºò,ËüµÄͼƬÐèÒªºóÃæ½øÐйÜÀí(Ìí¼Ó\ɾ³ýµÈ).ÊDz»ÊǵÃÎÒÃÇÊÖ¹¤È¥ÐÞ¸ÄdjangoµÄ¹ÜÀí´úÂëʵÏÖÔÚÒ»Æð±à¼­ÄØ?
×îºó,¶ÔÓÚtextFieldÀàÐ͵Ä×Ö¶Î,djangoĬÈÏÌṩµÄ±à¼­¹¤¾ßÖ»ÄÜÊÇ textareaÀàÐ͵Ä,Èç¹ûÐèÒªÀ©Õ¹·á¸»µÄ¹¤¾ß,ÔõôŪ±È½ÏºÃ?
ÒòΪ±È½Ï¼±×Å´¦Àí,ËùÒÔÏÈÇë½Ì´ó¼Ò,Ê¡µãʱ¼äÈ¥Ñо¿ÁË!
лл!
-------------- 下一部分 --------------
Ò»¸öHTML¸½¼þ±»ÒƳý...
URL: http://python.cn/pipermail/python-chinese/attachments/20070428/c866dddf/attachment.html 

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

2007年04月28日 星期六 07:18

limodou limodou在gmail.com
星期六 四月 28 07:18:10 HKT 2007

On 4/28/07, bbenyu <bbenyu在gmail.com> wrote:
>
>
> 请教大家一个问题:
> 在一般情况下,如果有二个类,假设product,一个产品具有多张图片,那么我目前是创建了一个析的模型productImages并且,在productimages中有字段
> product = models.ForeignKey(Product),不知道这样做是否比较好?

感觉没有问题。

> 另外,如果这样做了,django自带的后台管理,是依据不同的model进行创建的,那么在添加一个product时候,它的图片需要后面进行管理(添加\删除等).是不是得我们手工去修改django的管理代码实现在一起编辑呢?

admin有一个inline参数可以一次性编辑多个表。

> 最后,对于textField类型的字段,django默认提供的编辑工具只能是
> textarea类型的,如果需要扩展丰富的工具,怎么弄比较好?
> 因为比较急着处理,所以先请教大家,省点时间去研究了!
> 谢谢!

自已去加一些js的web editor,可以在网上搜到。

-- 
I like python!
UliPad <>: http://wiki.woodpecker.org.cn/moin/UliPad
My Blog: http://www.donews.net/limodou

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

2007年04月28日 星期六 08:49

黄毅 yi.codeplayer在gmail.com
星期六 四月 28 08:49:30 HKT 2007

On 4/28/07, bbenyu <bbenyu at gmail.com> wrote:
>
>  请教大家一个问题:
> 在一般情况下,如果有二个类,假设product,一个产品具有多张图片,那么我目前是创建了一个析的模型productImages并且,在productimages中有字段
> product = models.ForeignKey(Product),不知道这样做是否比较好?
>

Many-to-one relationships<http://www.djangoproject.com/documentation/model-api/#many-to-one-relationships>

另外,如果这样做了,django自带的后台管理,是依据不同的model进行创建的,那么在添加一个product时候,它的图片需要后面进行管理(添加\删除等).是不是得我们手工去修改django的管理代码实现在一起编辑呢?
>

见 Many-to-one relationships 里面的
edit_inline<http://www.djangoproject.com/documentation/model-api/#many-to-one-relationships>

最后,对于textField类型的字段,django默认提供的编辑工具只能是 textarea类型的,如果需要扩展丰富的工具,怎么弄比较好?
>

http://code.djangoproject.com/wiki/AddWYSIWYGEditor
http://code.google.com/p/django-fckconnector/ 里面有简单文档。

因为比较急着处理,所以先请教大家,省点时间去研究了!
> 谢谢!
>


-- 
http://codeplayer.blogspot.com/
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://python.cn/pipermail/python-chinese/attachments/20070428/2abdb4a2/attachment.html 

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

2007年04月28日 星期六 10:53

mvfirst mvfirst在126.com
星期六 四月 28 10:53:52 HKT 2007

´ó¼ÒºÃ£º
    ÎÒÓÃindex¶¯Ì¬Éú³ÉÒ»¸öÒ³Ãæ£¬¸ÃÒ³ÃæÒªÇóÓû§ÌîдÎı¾¿ò"test"£¨
µÈ¾ÍÊ¡ÂÔÁË£© Èç¹û testÄÚÈݲ»ºÏ¸ñ£¬¾ÍÒªÖØÐÂÐ޸쬵«Ò»µ©µ÷ÓÃHttpResponse(..)£¬¾ÍÓÖ´´½¨ÁËÒ»±ß£¬ ´ËʱtestÚ²¾Í»á±»Çå¿Õ£¬¶ø²»ÊÇÉÏ´ÎÓû§ÊäÈëµÄÄÚÈÝÁË¡£ Èç¹ûʹtest±£ÁôÉÏ´ÎÊäÈëµÄÄÚÈÝÄØ£¿µ±È»£¬³ÌÐò¶à×÷Щ´¦Àí¿ÉÒÔʵÏÖ£¬µ«ÊÇ·ñÓмòµ¥µÄ·½·¨£¿ def index(request): str_page = """
""" return HttpResponse(str_page£© -------------- 下一部分 -------------- Ò»¸öHTML¸½¼þ±»ÒƳý... URL: http://python.cn/pipermail/python-chinese/attachments/20070428/f3dc1c5a/attachment.htm

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

2007年04月28日 星期六 12:00

黄毅 yi.codeplayer在gmail.com
星期六 四月 28 12:00:35 HKT 2007

On 4/28/07, mvfirst <mvfirst at 126.com> wrote:
>
>  大家好:
>     我用index动态生成一个页面,该页面要求用户填写文本框"test"(
等就省略了) > 如果 test内容不合格,就要重新修改,但一旦调用HttpResponse(..),就又创建了一边, > 此时test诓就会被清空,而不是上次用户输入的内容了。 > 如果使test保留上次输入的内容呢?当然,程序多作些处理可以实现,但是否有简单的方法? > > def index(request): > str_page = """ >
> > > """ > return HttpResponse(str_page) > 区分一下 post 和 get 请求了, if request.POST: value = POST.get('test', '') if value and is_valid(value): return HttpRedirectResponse('success') else: return HttpResponse(str_page % value) return HttpResponse(str_page % '') -- http://codeplayer.blogspot.com/ -------------- next part -------------- An HTML attachment was scrubbed... URL: http://python.cn/pipermail/python-chinese/attachments/20070428/9a52f173/attachment.htm

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

2007年04月28日 星期六 12:00

Samuel Chi princeofdatamining在gmail.com
星期六 四月 28 12:00:44 HKT 2007

XMLHttpRequest

ÔÚ07-4-28£¬mvfirst <mvfirst在126.com> дµÀ£º
>
>  ´ó¼ÒºÃ£º
>     ÎÒÓÃindex¶¯Ì¬Éú³ÉÒ»¸öÒ³Ãæ£¬¸ÃÒ³ÃæÒªÇóÓû§ÌîдÎı¾¿ò"test"£¨
µÈ¾ÍÊ¡ÂÔÁË£© > Èç¹û testÄÚÈݲ»ºÏ¸ñ£¬¾ÍÒªÖØÐÂÐ޸쬵«Ò»µ©µ÷ÓÃHttpResponse(..)£¬¾ÍÓÖ´´½¨ÁËÒ»±ß£¬ > ´ËʱtestÚ²¾Í»á±»Çå¿Õ£¬¶ø²»ÊÇÉÏ´ÎÓû§ÊäÈëµÄÄÚÈÝÁË¡£ > Èç¹ûʹtest±£ÁôÉÏ´ÎÊäÈëµÄÄÚÈÝÄØ£¿µ±È»£¬³ÌÐò¶à×÷Щ´¦Àí¿ÉÒÔʵÏÖ£¬µ«ÊÇ·ñÓмòµ¥µÄ·½·¨£¿ > > def index(request): > str_page = """ >
> > > """ > return HttpResponse(str_page£© > > > _______________________________________________ > 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/20070428/4ce33d31/attachment.html

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

2007年04月28日 星期六 12:42

HackGou hackgou在163.com
星期六 四月 28 12:42:43 HKT 2007

一个HTML附件被移除...
URL: http://python.cn/pipermail/python-chinese/attachments/20070428/3cd727d2/attachment.html 

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

2007年04月28日 星期六 14:10

风向标 vaneoooo在gmail.com
星期六 四月 28 14:10:02 HKT 2007

POSTºÍget·½·¨ÊÇÒ»¸ö

Èç¹ûÒ»¶¨ÐèÒªPOSTµÄ»°£¬Ê¹ÓÃSESSIONÒ²²»´í
-------------- 下一部分 --------------
Ò»¸öHTML¸½¼þ±»ÒƳý...
URL: http://python.cn/pipermail/python-chinese/attachments/20070428/48e8fc42/attachment.htm 

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

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

    你的回复:

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

    Zeuux © 2025

    京ICP备05028076号