As far as I understand it, its just a helper to initialize a new object.
Some things to keep in mind:
- You don't /have/ to provide all parameters, if some of your columns have
default values you can only provide the required set of arguments
- You don't /have/ to do that but then when you want to setup a new model
object you will have to initialize them one by one:
places = Places()
places.url = ...
places.title = ...
and so on and so forth.
HTH
AM
On Sun, Feb 9, 2014 at 11:13 PM, Bao Niu <[email protected]> wrote:
> I'm new to sqlalchemy. I tried to search this question but didn't come up
> with accurate search terms. So I come here for some help from real people
> instead of search engine. For the following code:
>>
>> class Places(Base):
>>
>> """"""
>>
>> __tablename__ = 'moz_places'
>>
>>
>>
>> id = Column(Integer, primary_key=True)
>>
>> url = Column(String)
>>
>> title = Column(String)
>>
>> rev_host = Column(String)
>>
>> visit_count = Column(Integer)
>>
>> hidden = Column(Integer)
>>
>> typed = Column(Integer)
>>
>>
>>
>>
>>> #----------------------------------------------------------------------
>>
>> def __init__(self, id, url, title, rev_host, visit_count,
>>
>> hidden, typed):
>>
>> """"""
>>
>> self.id = id
>>
>> self.url = url
>>
>> self.title = title
>>
>> self.rev_host = rev_host
>>
>> self.visit_count = visit_count
>>
>> self.hidden = hidden
>>
>> self.typed = typed
>>
>>
> If I already defined each column names as class variable, why do I still
> need to re-define each of them as instance variables? I just can't
> understand the reason. Any hint would be highly appreciated. Thanks.
>
> --
> You received this message because you are subscribed to the Google Groups
> "sqlalchemy" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to [email protected].
> To post to this group, send email to [email protected].
> Visit this group at http://groups.google.com/group/sqlalchemy.
> For more options, visit https://groups.google.com/groups/opt_out.
>
--
You received this message because you are subscribed to the Google Groups
"sqlalchemy" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/sqlalchemy.
For more options, visit https://groups.google.com/groups/opt_out.