I use: Python 2.6 and sqlalchemy 0.6.1
This is what I am trying to do: - from sqlalchemy.types import (
-
Integer,
-
String,
-
Boolean
-
)
-
from sqlalchemy.ext.declarative import declarative_base
-
-
Base = declarative_base()
-
-
class SampleMeta(type):
-
def __new__(cls, name, bases, attrs):
-
attrs.update({ 'id': Column('Id', Integer, primary_key=True),
-
'name': Column('Name', String),
-
'description': Column('Description', String),
-
'is_active': Column('IsActive', Boolean)
-
})
-
return super(SampleMeta, cls).__new__(cls, name, bases, attrs)
-
-
class Sample(Base):
-
__tablename__ = 'Sample'
-
__table_args__ = {'useexisting': True}
-
__metaclass__ = SampleMeta
-
-
def __init__(self, id, name, description, is_active):
-
self.id = id
-
self.name = name
-
self.description = description
-
self.is_active = is_active
-
-
def __repr__(self):
-
return "<(%d, '%s', '%s', %r)>" % (self.id, self.name, self.description, self.isactive)
And the error I am getting is this: - TypeError: Error when calling the metaclass bases
-
metaclass conflict: the metaclass of a derived class must be a (non-strict) subclass of the metaclasses of all its bases
-
Now, if I do the same thing above by using
instead of
it works absolutely fine.
I need to update the attributes of the class dynamically. So, I will be using dynamic attribute and column names. And I need the above piece code to work in order to be able to get there.
**Please help**
0 1130 Sign in to post your reply or Sign up for a free account.
Similar topics
by: saurabh |
last post by:
solve a problem:
define a Class(MyClassSArray a, b, c) which implements an array of string.
But, in the backend it is actually implementing Linked List, so that memory
is dynamically allocated....
|
by: Bhan |
last post by:
Using Ptr of derived class to point to base class and viceversa
class base
{
....
}
class derived : public base
{
....
}
|
by: Jonah Olsson |
last post by:
Dear Sirs,
I'm looking for a way to define a class using an XML file. Since I'm
building a Web Service to be used by several customers I want to be able to
easily change the class below without...
|
by: Rob |
last post by:
In many articles related to VB.net the word "class" is used...
How many meanings are there to this word ?
"possible to derived a class from another"
"forms are full-fledged classes"
"base...
|
by: vilarneto |
last post by:
Hello everyone,
I'm facing a particular situation about template class derivation.
The subject is old -- deriving a non-template class from a template
base class -- but my problem is that the...
|
by: murl |
last post by:
I want to create a web user control with a base class of 'GridView' so
I can wrap the needed methods to make rows clickable. However when
building the project I get the following message:
"Make...
|
by: shofu_au |
last post by:
Hi Group,
I am trying to define a class that has a fixed size array of a
structure containing a fixed size array of a structure.
I am using System.Runtime.InteropServices and trying to define...
|
by: =?Utf-8?B?R2Vvcmdl?= |
last post by:
Hello everyone,
I met with a strange issue that derived class function can not access base
class's protected member. Do you know why?
Here is the error message and code.
error C2248:...
|
by: Immortal Nephi |
last post by:
The rule of inheritance states that you define from top to bottom.
Sometimes, you want to define base class and set reference from
dervied class to base class, but you violate the rule.
Here is an...
|
by: Peng Yu |
last post by:
Hi,
Suppose I have two namespaces A and B, I'm wondering if I can define a
class in B for A. The question is relevant when I want to specialize
some classes that have been defined in the std::...
|
by: DolphinDB |
last post by:
Tired of spending countless mintues downsampling your data? Look no further!
In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
|
by: ryjfgjl |
last post by:
ExcelToDatabase: batch import excel into database automatically...
|
by: isladogs |
last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM).
In this month's session, we are pleased to welcome back...
|
by: isladogs |
last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM).
In this month's session, we are pleased to welcome back...
|
by: Vimpel783 |
last post by:
Hello!
Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
|
by: jfyes |
last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
|
by: ArrayDB |
last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
|
by: CloudSolutions |
last post by:
Introduction:
For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
|
by: Defcon1945 |
last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
| |