I am trying to formulate a datamigration for one of my apps. I am using the reputation system mentioned here - django-reputation
我正在为我的一个应用程序制定一个数据模型。我使用的是这里提到的声誉系统——django-reputation
in my forward
method, I have the following code -
在我的forward方法中,我有以下代码-
orm['reputation.reputation'].objects.log_reputation_action(user = user_x, originating_user = user_y, action_value = 10, target_object = sample_obj)
but while running the migration, I get the following error -
但是在运行迁移时,我得到了以下错误。
AttributeError: 'Manager' object has no attribute 'log_reputation_action'
I have freezed the reputation
app in the datamigration. Please let me know what I am doing wrong here.
我已经在datamigration中冻结了声誉应用程序。请让我知道我在这里做错了什么。
Thanks in advance.
提前谢谢。
2 个解决方案
#1
1
Looks like this is not possible.
看来这是不可能的。
From the South documentation:
来自南方的文档:
You can do a lot more with this inside a data migration; any model can be available to you. The only caveat is that you won’t have access to any custom methods or managers on your models, as they’re not preserved as part of the freezing process (there’s no way to do this generally); you’ll have to copy any code you want into the migration itself. Feel free to make them methods on the Migration class; South ignores everything apart from forwards and backwards.
你可以在数据迁移中做更多的事情;任何型号都可以提供给您。唯一要注意的是,您将无法访问模型上的任何自定义方法或管理器,因为它们不是冻结过程的一部分(通常无法做到这一点);您将不得不将您想要的任何代码复制到迁移本身中。您可以在迁移类上随意使用它们;南风从前到后忽略了一切。
#2
0
Since Django 1.8, you can include model managers in migrations by adding the use_in_migrations property.
由于Django 1.8,您可以通过添加use_in_migrations属性在迁移中包含模型管理器。
From the docs: https://docs.djangoproject.com/en/2.0/topics/migrations/#model-managers
从文档:https://docs.djangoproject.com/en/2.0/topics/migrations/ #模型管理员
class MyManager(models.Manager):
use_in_migrations = True
class MyModel(models.Model):
objects = MyManager()
#1
1
Looks like this is not possible.
看来这是不可能的。
From the South documentation:
来自南方的文档:
You can do a lot more with this inside a data migration; any model can be available to you. The only caveat is that you won’t have access to any custom methods or managers on your models, as they’re not preserved as part of the freezing process (there’s no way to do this generally); you’ll have to copy any code you want into the migration itself. Feel free to make them methods on the Migration class; South ignores everything apart from forwards and backwards.
你可以在数据迁移中做更多的事情;任何型号都可以提供给您。唯一要注意的是,您将无法访问模型上的任何自定义方法或管理器,因为它们不是冻结过程的一部分(通常无法做到这一点);您将不得不将您想要的任何代码复制到迁移本身中。您可以在迁移类上随意使用它们;南风从前到后忽略了一切。
#2
0
Since Django 1.8, you can include model managers in migrations by adding the use_in_migrations property.
由于Django 1.8,您可以通过添加use_in_migrations属性在迁移中包含模型管理器。
From the docs: https://docs.djangoproject.com/en/2.0/topics/migrations/#model-managers
从文档:https://docs.djangoproject.com/en/2.0/topics/migrations/ #模型管理员
class MyManager(models.Manager):
use_in_migrations = True
class MyModel(models.Model):
objects = MyManager()