Django models into web2py

115 views
Skip to first unread message

Ron Chatterjee

unread,
Mar 27, 2015, 4:56:05 PM3/27/15
to web...@googlegroups.com
This is an old web2py blog.


Did anyone went through the steps and was able to generate the tables? I tried but it failed. It didn't work. Is it only valid for polls example only or any django models can be used in web2py this way? Not sure. 

I know its not a recommended and I will never deploy an application using this method. But wanted to try few django projects and code them up in web2py to learn more but I am and kind of feeling lazy to write the table from scratch. thought copy and paste will be nice if I can get this method to work. Any web2pier wants to try and see what I am doing wrong?

I get an error saying:

models/db.py", line 62, in <module>
class Poll(Model):
File "applications\try_django_polls\modules\django.py", line 145, in __new__
fields=[db.Field(key,**value.serial(name,db)) for key,value in attrs.items() if hasattr(value,'serial') and not isinstance(value,ManyToManyField)]
File "...\Desktop\web2py_src\web2py\gluon\dal\base.py", line 893, in __getattr__
return ogetattr(self, key)
AttributeError: 'DAL' object has no attribute 'Field' 

Phyo Arkar

unread,
Mar 27, 2015, 9:39:16 PM3/27/15
to web2py

The example is very old and too many changes neede.
Even after the deprecated fixes , DjangoModelFactory not working anymore

it have this error:

Traceback (most recent call last):
  File "/home/v3ss/workspace/web2py/gluon/restricted.py", line 224, in restricted
    exec ccode in environment
  File "applications/otwopy/models/db.py", line 91, in <module>
    class Poll(Model):
  File "applications/otwopy/modules/django.py", line 229, in __new__
    table = db.define_table(name, migrate=migrate, *fields)
  File "/home/v3ss/workspace/web2py/gluon/dal/base.py", line 787, in define_table
    table = self.lazy_define_table(tablename,*fields,**args)
  File "/home/v3ss/workspace/web2py/gluon/dal/base.py", line 804, in lazy_define_table
    table = table_class(self, tablename, *fields, **args)
  File "/home/v3ss/workspace/web2py/gluon/dal/objects.py", line 327, in __init__
    'define_table argument is not a Field or Table: %s' % field)
SyntaxError: define_table argument is not a Field or Table: <no table>.name

.

On Sat, Mar 28, 2015 at 3:26 AM, Ron Chatterjee achatte...@gmail.com wrote:

This is an old web2py blog.

http://www.web2py.com/AlterEgo/default/show/189

Did anyone went through the steps and was able to generate the tables? I
tried but it failed. It didn’t work. Is it only valid for polls example only
or any django models can be used in web2py this way? Not sure.

I know its not a recommended and I will never deploy an application using
this method. But wanted to try few django projects and code them up in
web2py to learn more but I am and kind of feeling lazy to write the table
from scratch. thought copy and paste will be nice if I can get this method
to work. Any web2pier wants to try and see what I am doing wrong?

I get an error saying:

models/db.py”, line 62, in

class Poll(Model):
File “applications\trydjangopolls\modules\django.py”, line 145, in
new


fields=[db.Field(key,**value.serial(name,db)) for key,value in
attrs.items() if hasattr(value,’serial’) and not
isinstance(value,ManyToManyField)]

File “…\Desktop\web2py_src\web2py\gluon\dal\base.py”, line 893, in
__getattr

return ogetattr(self, key)

AttributeError: ‘DAL’ object has no attribute ‘Field’


Resources:


You received this message because you are subscribed to the Google Groups
“web2py-users” group.
To unsubscribe from this group and stop receiving emails from it, send an
email to web2py+un...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

django.py

Phyo Arkar

unread,
Mar 27, 2015, 9:39:38 PM3/27/15
to web2py
attached is the fixed django.py . 

Ron Chatterjee

unread,
Mar 27, 2015, 9:49:53 PM3/27/15
to web...@googlegroups.com
Yes, I tried the code and it gave me the same error as well. So the problem is with the djangomodelfactory. I see.

Massimo Di Pierro

unread,
Mar 28, 2015, 12:23:55 PM3/28/15
to web...@googlegroups.com
This is a backward compatibility problem in the latest web2py. Should be fixed in the nightly build (for testers)

Phyo Arkar

unread,
Mar 28, 2015, 1:44:28 PM3/28/15
to web2py
Thanks a lot massimo , i will try with latest nightly then.

--
Resources:
- http://web2py.com
- http://web2py.com/book (Documentation)
- http://github.com/web2py/web2py (Source code)
- https://code.google.com/p/web2py/issues/list (Report Issues)
---

Ron Chatterjee

unread,
Mar 28, 2015, 3:17:53 PM3/28/15
to web...@googlegroups.com
That will be great. Then we can also do django development using web2py interface. you rock massimo!

Phyo Arkar

unread,
Mar 28, 2015, 4:28:24 PM3/28/15
to web2py
Web2py DAL is actually a lot more powerful. i use web2py DAL anywhere even if it is not for web or non web2py project.

--

Ron Chatterjee

unread,
Mar 28, 2015, 9:35:15 PM3/28/15
to web...@googlegroups.com
I agree with Phyo. Syntax is lot better and readable and close to sql than ORM

Ron Chatterjee

unread,
Apr 4, 2015, 11:50:56 AM4/4/15
to web...@googlegroups.com
I believe there is a way:One thing we can do is to after we create the model in web2py, there is a log file call SQL log. Someone can copy that and after creating a project in django, open up the settings.py and paste that in there.

After that, just type in:
python manage.py inspectdb > models.py

Which will generate models.py. Then someone can synch the db 
and create the app. 

Here is the link:

https://docs.djangoproject.com/en/1.7/howto/legacy-databases/

 The other direction is much simpler. Once the django model files are generated. Someone can do:

python scripts/extract_mysql_models.py username:password@databasename > db1.py

I haven't tried either or. Will be interested to see what others find out.
Reply all
Reply to author
Forward
0 new messages