On Fri, Jun 29, 2018 at 3:35 PM, Marcus Mann <[email protected]> wrote:
> Does that make more sense of what I am trying to do Mike?
oh disregard my last email , these two appeared after I answered.
Still not really sure I understand what you want to do. When would
you refer to FracturedBone.description? is that still a column ? or
you don't want to persist it when you deal with a FracturedBone ?
would need to know from a SQL / usage perspective what that means.
>
> On Friday, June 29, 2018 at 12:02:38 PM UTC-4, Marcus Mann wrote:
>>
>> What is the difference between a column property and a column? Does A.data
>> statically refer to the "A" table? What I want to do is basically do
>> something like
>>
>> from sqlalchemy import Column, Integer, String
>> from sqlalchemy.ext.declarative import declarative_base
>>
>> Base = declarative_base()
>>
>>
>> class Item(Base):
>> __tablename__ = 'users'
>>
>> id = Column(Integer, primary_key=True)
>> name = Column(String)
>> cost = Column(String)
>> amount = Column(String)
>> description = Column(String, default="Item")
>> type = Column(String)
>> __mapper_args__ = {
>> 'polymorphic_on': type,
>> 'polymorphic_identity': 'item'
>> }
>>
>> def __str__(self):
>> return f"{self.amount}x {self.name}"
>>
>>
>> class FracturedBone(Item):
>> name = "Fractured Bone"
>> cost = 15
>> amount = 1
>> description = "A crooked old bone with a large crack in the middle"
>> __mapper_args__ = {
>> 'polymorphic_on': type,
>> 'polymorphic_identity': 'item'
>> }
>> def cool_funtion(self):
>> print("Cool!")
>>
>>
>> So I want to set the defaults in the child class, but I don't know how.
>>
>>
>> On Friday, June 29, 2018 at 9:49:07 AM UTC-4, Mike Bayer wrote:
>>>
>>> your question is getting no answers because it is vague and doesn't
>>> provide any code. what's a "description"? you mean a Python
>>> docstring ? Python attributes don't have a __doc__ normally, if you
>>> mean the "doc" parameter, just make a separate property:
>>>
>>> class A(Base):
>>> __tablename__ = 'a'
>>>
>>> id = Column(Integer, primary_key=True)
>>>
>>> data = column_property(Column(String), doc="the data")
>>>
>>>
>>> class B(A):
>>> __tablename__ = 'b'
>>>
>>> id = Column(ForeignKey('a.id'), primary_key=True)
>>>
>>> data = column_property(A.data, doc="B's data")
>>>
>>>
>>>
>>>
>>> On Fri, Jun 29, 2018 at 8:41 AM, Marcus Mann <[email protected]> wrote:
>>> >
>>> > https://stackoverflow.com/questions/51046900/how-to-access-override-defaults-on-parents-attribute-in-sql-alchemy
>>> >
>>> > --
>>> > SQLAlchemy -
>>> > The Python SQL Toolkit and Object Relational Mapper
>>> >
>>> > http://www.sqlalchemy.org/
>>> >
>>> > To post example code, please provide an MCVE: Minimal, Complete, and
>>> > Verifiable Example. See http://stackoverflow.com/help/mcve for a full
>>> > description.
>>> > ---
>>> > 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 https://groups.google.com/group/sqlalchemy.
>>> > For more options, visit https://groups.google.com/d/optout.
>
> --
> SQLAlchemy -
> The Python SQL Toolkit and Object Relational Mapper
>
> http://www.sqlalchemy.org/
>
> To post example code, please provide an MCVE: Minimal, Complete, and
> Verifiable Example. See http://stackoverflow.com/help/mcve for a full
> description.
> ---
> 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 https://groups.google.com/group/sqlalchemy.
> For more options, visit https://groups.google.com/d/optout.
--
SQLAlchemy -
The Python SQL Toolkit and Object Relational Mapper
http://www.sqlalchemy.org/
To post example code, please provide an MCVE: Minimal, Complete, and Verifiable
Example. See http://stackoverflow.com/help/mcve for a full description.
---
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 https://groups.google.com/group/sqlalchemy.
For more options, visit https://groups.google.com/d/optout.