On Saturday, July 24, 2010 17:22:33 bloeper wrote:
> Hi All,
> 
> Sorry for my question flood, but I am trying to get this to work.
> I have the following init in a blog model:
> def __init__( self, title, content, user_id):
>       self.title = title
>       self.slug = urlify( title )
>       self.date = datetime.now()
>       self.content = content
>       self.user_id = user_id
> 
> When i create some default records with the web-setup it works fine,
> but when I try to add a record trough the web admin i get the error
> that the init function expects 4 parameters and that 1 is given.
> How does the admin add records?
> In the admin I do fill in all the fields, but it seems to me it posts
> those parameters in one list or something...
> Anyone got an idea how to fix this...
> I need the init to work because of the urlify function I use. (this
> function makes from the title a save url)
> For instance: Test blog goes through urlify and the output becomse:
> test-blog

I think you violate the design of SA declarative here. You there create an 
instance & *then* set it's attributes. You do not use a rich __init__.

And your reasoning for using a rich __init__ instead is flawed - if you'd need 
the urlify for slug, you'd certainly also need it for setting it on an 
existing instance.

So the solution to this is simple. Make slug a property. I'm not sure what the 
best way to do this is in declarative, my attempt would simply be do declare a 
private attribute _slug (with DB-name slug), and then do the usual property 
getter/setter stuff to create slug.

Diez

-- 
You received this message because you are subscribed to the Google Groups 
"TurboGears" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/turbogears?hl=en.

Reply via email to