简体   繁体   English

管理工厂 Django

[英]Managing Django Factories

Would there be an issue with including a factory in the model class itself?在 model class 本身中包含一个工厂会有问题吗? I know it's valid python but I'm not sure it would break anything in Django. My initial testing shows it works fine, but I haven't seen examples online doing it this way.我知道它是有效的 python,但我不确定它会破坏 Django 中的任何内容。我的初步测试表明它工作正常,但我还没有在网上看到这样的例子。

class SampleModel(models.Model):
    ....
    class Factory(factory.django.DjangoModelFactory):
        ....

I believe it won't break anything, but in my opinion, keeping factories together with models doesn't look good.我相信它不会破坏任何东西,但在我看来,让工厂和模型在一起看起来不太好。 I think it's cleaner to split them and put factories closer to tests rather than the models.我认为将它们分开并让工厂更接近测试而不是模型更清洁。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM