Thanks to all comments to my previous post, I managed to further simplify the model.
Changes:
- I don’t have to define any variables for the model classes.
- The session and metadata are imported from TurboGears.
Same functionality as before, but shorter (model.py at the bottom of the post).
A developer who doesn’t write unit tests will for sure write a bunch of hard to find bugs with a dynamically typed language like Python (like setting a wrong variable before an update: project.ttle=title). But hey, If it’s not tested, it’s broken.
Bruce Eckel has a good article for Java developers about weak typing: Strong Typing vs. Strong Testing
model.py (compare to previous SQLAlchemy version ):
from sqlalchemy import *
from sqlalchemy.ext.assignmapper import assign_mapper
import turbogears
from turbogears.database import metadata, session
...
#same table definitions as before
...
class Project(object):
pass
class Action(object):
pass
class Tag(object):
pass
class Context(object):
pass
assign_mapper(session.context,Tag, tags)
actionmapper = assign_mapper(session.context,Action, actions, properties = {
'tags' : relation(Tag, secondary=tagaction)
})
projectmapper = assign_mapper(session.context,Project, projects, properties={
'actions' : relation(Action, backref='project', order_by=actions.c.priority),
})
contextmapper = assign_mapper(session.context,Context, contexts, properties={
'actions' : relation(Action, backref='context'),
})
It looks as if the link to “previous SQLAlchemy version” is broken.
thanks! fixed.
I love your site!
_____________________
Experiencing a slow PC recently? Fix it now!
My brother suggested I may like this web site. He was once entirely right.
This submit actually made my day. You can not believe simply how so much time I had spent for this information!
Thanks!
Hi there to every single one, it’s actually a good for me to pay a visit this web page, it consists of important Information.
Hi! I know this is somewhat off-topic but I had to ask.
Does running a well-established website such as yours
require a lot of work? I’m brand new to running a blog but I do write in my journal daily. I’d
like to start a blog so I can share my own experience and thoughts
online. Please let me know if you have any kind of suggestions or tips for brand new
aspiring blog owners. Thankyou!
Hello! Someone in my Facebook group shared this website with us so I
came to take a look. I’m definitely loving the information. I’m bookmarking and will be
tweeting this to my followers! Wonderful blog and superb style and design.
Hey, I think your website might be having browser
compatibility issues. When I look at your website in Firefox,
it looks fine but when opening in Internet Explorer, it has some overlapping.
I just wanted to give you a quick heads up! Other then that, very good blog!
I visited plenty of website but I this one this one holds lots of useful points.
Howdy just wanted to give you a quick heads up. The text in your article seem to
be running off the screen in Opera. I’m not sure if this is a formatting issue or something to do with internet browser compatibility but I thought I’d post to let you know.
The design and style look great though! Hope you get the problem fixed soon.
Many thanks
Hola! I’ve been reading your website for some time now and finally got the courage to go ahead and give you a shout out from Lubbock Texas! Just wanted to say keep up the great work!
Wow! I’m really enjoying the design of your website. Are you using a customized theme or is this readily available to all individuals? If you really don’t want
to say the name of it out in the public, please make sure to email
me at: hazeljaramillo@gmail.com. I’d absolutely love to get my hands on this template! Bless you.
Hello! It appears as though we both have a interest for the same thing.
Your blog, “Simplifying the model with assign_mapper | From Java to Python” and
mine are very similar. Have you ever considered writing a guest article for a similar blog?
It will surely help gain publicity to your blog (my site recieves a lot
of visitors). If you are interested, email me at:
lawerencechristmas@gmail.com. Thank you so much
Write more, thats all I have to say. Literally, it seems as though you relied on
the video to make your point. You clearly know what
youre talking about, why waste your intelligence on just posting
videos to your weblog when you could be giving us something informative to read?