我在各种问题上进行了很好的挖掘,似乎缺少我觉得一定很明显的东西。
在Postgres中,使用python,sqlalchemy和Factoryboy进行运行(现在失败)测试,我有两个表模型...
letter
是实例化的 它扩展了 file
:
类字母(文件):
-
和 file
又扩展了SQL Alchemys dectarativeBase
:
class File (dectarativebase):
-
在文件
中,是一个称为 content_type
的属性。
content_type
现在已在文件
上设置为不是可确定的
。
-
我需要做的事情感觉非常基本...
字母
,我需要将默认的 content_type
设置为“应用程序” /pdf“
... 就是这样!
,但对于我的所有尝试,我似乎都无法将其设置为 letter
的默认内容类型
这意味着我们已经运行的测试,无法尝试创建 file
,因为它没有 content_type
可以传递到 file> file
,这意味着我得到 notnullviolation
。
我尝试以几种不同的方式在字母
模型中设置此设置,但无济于事。
-
方法:
- 我尝试使用
__ INT __
在 file> file
的自定义基础模型中以及 inters> letter
中尝试使用。使用 kawgs
并尝试以这种方式设置它,尽管这不起作用。
- 我已经考虑过将列添加到
字母
模型中,但是这会击败第三个正常形式,因此我认为有更好的方法可以做到这一点。
- 我试图通过我们正在运行的测试中传递值,但是没有运气(测试使用
Factoryboy
)
- 有一个
letterfactory
(来自 Factory> Factoryboy
)这是问题的来源,我尝试将 content_type =“ application/pdf”
添加到此中,而没有任何运气。
- 我还尝试在
Factoryboy -LetterFactory
中再次设置 content_type
,再次:
class Meta(SQLAlchemyOptions):
model = Letter
model.content_type = "application/pdf"
- 在
Letter> Letter> Letter
模型本身中,我包括跟随,也没有任何运气:
@property
def content_type(self):
return "application/pdf"
-
对我认为可能是一个基本问题表示歉意。
任何指针都会非常受欢迎。
这也许只是我不熟悉SQL炼金术中正确的术语并缺少明显的情况。
有人了解我的问题,并有任何可以给我的线程吗?
I've had a good dig around various questions and seem to be missing something that I feel must be fairly obvious.
In Postgres, using Python, SQLAlchemy and FactoryBoy to run (now failing) tests, I have two table models...
When Letter
is instantiated, it extends File
:
class Letter(File):
--
and File
in turn extends SQL Alchemys DeclarativeBase
:
class File(DeclarativeBase):
--
Within File
, is a property called content_type
.
content_type
has now been set on File
to be not nullable
.
--
What I need to do feels very basic...
Within Letter
, I need to set the default content_type
to "application/pdf"
... that's it!
However, for all my trying, I cannot seem to get it to set this as the default content type for Letter
This means that tests we have running, fail on trying to create the File
as it has no content_type
to pass over to File
, meaning I get aNotNullViolation
.
I have tried setting this within the Letter
model in a few different ways, but to no avail.
--
Approaches:
- I tried using
__init__
in both the Custom Base model of File
and as well as in Letter
using kawgs
and attempting to set it that way, though this did not work.
- I have thought about adding the column into the
Letter
model, but this defeats Third Normal Form so I assume there is a better way to do it.
- I have attempted to pass the value through the test we are running but without any luck (tests are using
FactoryBoy
)
- There is a
LetterFactory
(from FactoryBoy
) which is where the issue is coming from, I have attempted to add content_type = "application/pdf"
to this without any luck.
- I have also attempt to set the
content_type
on the model return in the FactoryBoy - LetterFactory
, again :
class Meta(SQLAlchemyOptions):
model = Letter
model.content_type = "application/pdf"
- Within the
Letter
model itself, I included the following, also without any luck:
@property
def content_type(self):
return "application/pdf"
--
Apologies on what I think might be a basic question.
Any pointers would be very welcomed.
It's perhaps just a case of me not being familiar with the right terminology in SQL Alchemy and missing the obvious.
Does anyone understand my issue and have any threads they could give me to pull on?
发布评论
评论(1)
这对我有用,最初我一定有一些错误:
文件(base):
letter(file):
This worked for me, I must have got something wrong initially:
File(Base):
Letter(File):