[PonyORM-list] problems with Date field defenition

Вадим Бажов vadim at ideco.ru
Thu Jul 31 11:40:56 UTC 2014


Yes, optionally. But i prefere to stay on a safe side and avoid using 
'date' word at all. Thanks again.

31.07.2014 17:33, Alexander Kozlovsky пишет:
> Actually `date` is not a reserved word in Python, so if you really 
> want it to be named 'date', you can do it as in the following:
>
>     import datetime
>
>     ...
>     class MyEntity(db.Entity):
>         date = Required(datetime.date)
>
> This way you can avoid name conflict. But renaming 'date' attribute is 
> the valid way too.
>
>
> On Thu, Jul 31, 2014 at 3:13 PM, Вадим Бажов <vadim at ideco.ru
> <mailto:vadim at ideco.ru>> wrote:
>
>     Yes, my fault ! Thank you Alexander.
>     And the second mistake is the 'date' name for the field variable.
>     It's reserved in python. I had to rename it to 'insdate' and now
>     everithyng works fine.
>     Thanks a lot for the Pony ORM and immediate support ))
>
>     31.07.2014 16:55, Alexander Kozlovsky пишет:
>>     Hi Vadim!
>>
>>     The datatype that is specifed in attribute definition is a normal
>>     Python type. In Python, `int` and `str` types can be used
>>     immediately, but `date` and `datetime` types must be imported
>>     from stadard `datetime` module.
>>
>>     You can add this import to the beginning of your program:
>>
>>         from datetime import date, datetime
>>
>>     After that, all should work without the exception:
>>
>>     date = Required(date)
>>         updated_at = Optional(datetime)
>>
>>     Alternatively, you can just import `datetime` module itself:
>>
>>         import datetime
>>
>>     After that, refer to `date` and `datetime` types as
>>     `datetime.date` and `datetime.datetime`:
>>
>>     date = Required(datetime.date)
>>         updated_at = Optional(datetime.datetime)
>>
>>     Regards,
>>     Alexander Kozlovsky
>>
>>
>>
>>     On Thu, Jul 31, 2014 at 2:33 PM, Вадим Бажов <vadim at ideco.ru
>>     <mailto:vadim at ideco.ru>> wrote:
>>
>>         Hi people !
>>
>>         Whenever i create a date or datetime field in entity python
>>         always gives me an exception:
>>
>>         "NameError: name 'date' is not defined" for "date =
>>         Required(date)" record according your documentation documentation
>>
>>         "pony.orm.core.ERDiagramError: Entity definition date was not
>>         found" for "date = Required('date')"
>>
>>         I am trying to run i file with folowing code:
>>
>>         #!/usr/bin/python
>>
>>         # -*- coding: utf-8 -*-
>>
>>         from pony.orm import *
>>
>>         db = Database('sqlite', 'db.sqlite', create_db=True)
>>
>>         class subscribers(db.Entity):
>>
>>             id = PrimaryKey(int, auto=True)
>>
>>             email   = Optional(str)
>>
>>             date = Required(date)
>>
>>         sql_debug(True)
>>
>>         db.generate_mapping(create_tables=True)
>>
>>
>>         Running that code from python shell gives me the following:
>>
>>                     from pony.orm import *
>>
>>
>>                     db = Database('sqlite', '/tmp/db.sqlite',
>>                     create_db=True)
>>
>>
>>         GET NEW CONNECTION
>>
>>         RELEASE CONNECTION
>>
>>                     class subscribers(db.Entity):
>>
>>
>>         ...     id = PrimaryKey(int, auto=True)
>>
>>         ...     email   = Optional(str)
>>
>>         ...     date = Required('date')
>>
>>         ...
>>
>>                     sql_debug(True)
>>
>>
>>                     db.generate_mapping(create_tables=True)
>>
>>
>>         Traceback (most recent call last):
>>
>>           File "<stdin>", line 1, in <module>
>>
>>           File "<auto generated wrapper of generate_mapping()
>>         function>", line 2, in generate_mapping
>>
>>           File
>>         "/usr/local/lib/python2.7/dist-packages/pony/orm/core.py",
>>         line 2698, in _resolve_attr_types_
>>
>>             throw(ERDiagramError, 'Entity definition %s was not
>>         found' % py_type)
>>
>>           File
>>         "/usr/local/lib/python2.7/dist-packages/pony/utils.py", line
>>         126, in throw
>>
>>             raise exc  # Set "pony.options.CUT_TRACEBACK = False" to
>>         see full traceback
>>
>>         pony.orm.core.ERDiagramError: Entity definition date was not
>>         found
>>
>>
>>         So database can't be created after all.
>>
>>         Pony version installed with pip:
>>
>>         pony                      - Pony Object-Relational Mapper
>>
>>           INSTALLED: 0.5.1
>>
>>           LATEST:    0.5-beta
>>
>>         Is it a bug or something? How i should create a datefield
>>         with Pony ?
>>
>>         I've couldn't create a table with several tables with Pony
>>         until i commented out all datefields strings from the code.
>>         So Pony works if i don't use datetime fields.
>>
>>
>>         -- 
>>         С уважением,
>>         Бажов Вадим,
>>         Инженер отдела технической поддержки,
>>         Компания Айдеко
>>         --
>>         Телефоны: +7 (495) 987-32-70; +7 (495) 662-87-34 (тех.
>>         поддержка); +7 (343) 345-15-75; Факс: +7 (343) 383-75-13
>>
>>         Электронная почта:
>>         Вопросы по приобретению: sales at ideco.ru <mailto:sales at ideco.ru>
>>         Технические вопросы: support at ideco.ru <mailto:support at ideco.ru>
>>         Партнерство: partners at ideco.ru <mailto:partners at ideco.ru>
>>         Общие вопросы: info at ideco.ru <mailto:info at ideco.ru>
>>
>>         Сайт: http://www.ideco.ru/
>>         Форум: http://www.ideco.ru/forum/
>>
>>         _______________________________________________
>>         ponyorm-list mailing list
>>         ponyorm-list at ponyorm.com <mailto:ponyorm-list at ponyorm.com>
>>         /ponyorm-list
>>
>>
>>
>>
>>     _______________________________________________
>>     ponyorm-list mailing list
>>     ponyorm-list at ponyorm.com  <mailto:ponyorm-list at ponyorm.com>
>>     /ponyorm-list
>
>     -- 
>     С уважением,
>     Бажов Вадим,
>     Инженер отдела технической поддержки,
>     Компания Айдеко
>     --
>     Телефоны: +7 (495) 987-32-70; +7 (495) 662-87-34 (тех. поддержка); +7 (343) 345-15-75; Факс: +7 (343) 383-75-13
>
>     Электронная почта:
>     Вопросы по приобретению:sales at ideco.ru  <mailto:sales at ideco.ru>
>     Технические вопросы:support at ideco.ru  <mailto:support at ideco.ru>
>     Партнерство:partners at ideco.ru  <mailto:partners at ideco.ru>
>     Общие вопросы:info at ideco.ru  <mailto:info at ideco.ru>
>
>     Сайт:http://www.ideco.ru/
>     Форум:http://www.ideco.ru/forum/  
>
>
>     _______________________________________________
>     ponyorm-list mailing list
>     ponyorm-list at ponyorm.com <mailto:ponyorm-list at ponyorm.com>
>     /ponyorm-list
>
>
>
>
> _______________________________________________
> ponyorm-list mailing list
> ponyorm-list at ponyorm.com
> /ponyorm-list

-- 
С уважением,
Бажов Вадим,
Инженер отдела технической поддержки,
Компания Айдеко
--
Телефоны: +7 (495) 987-32-70; +7 (495) 662-87-34 (тех. поддержка); +7 (343) 345-15-75; Факс: +7 (343) 383-75-13

Электронная почта:
Вопросы по приобретению: sales at ideco.ru
Технические вопросы: support at ideco.ru
Партнерство: partners at ideco.ru
Общие вопросы: info at ideco.ru

Сайт: http://www.ideco.ru/
Форум: http://www.ideco.ru/forum/

-------------- next part --------------
An HTML attachment was scrubbed...
URL: </ponyorm-list/attachments/20140731/f5fa21f1/attachment-0001.html>


More information about the ponyorm-list mailing list