我已經寫了自定義模塊用於這一目的
所有你需要的是將其保存在一些utils的/模型上__init__.py
文件。db和您的所有車型,而不是from django.db import models
寫from utils import models
如果有人有興趣的話,我可以寫一個組件併發布PyPI上
UPD:試試這個https://github.com/FeroxTL/django-migration-control
# models.py
# -*- coding: utf-8 -*-
from types import FunctionType
from django.db import models
class NoMigrateMixin(object):
"""
Позволяет исключить из миграций различные поля
"""
def deconstruct(self):
name, path, args, kwargs = super(NoMigrateMixin, self).deconstruct()
kwargs.pop('help_text', None)
kwargs.pop('verbose_name', None)
return name, path, args, kwargs
# =============================================================================
# DJANGO CLASSES
# =============================================================================
for name, cls in models.__dict__.items():
if isinstance(cls, type):
if issubclass(cls, models.Field):
# Поля
globals()[name] = type(name, (NoMigrateMixin, cls), {})
else:
# Всякие менеджеры
globals()[name] = cls
elif isinstance(cls, FunctionType):
# Прочие функции
globals()[name] = cls
從andrewgodwin此評論回答了這個問題,但部分我仍然希望能夠更改'help_text'而無需更新遷移:https://code.djangoproject.com/ticket/21498#comment:6 – utapyngo 2014-10-22 09:55:26