I started writing my first reusable application about 3 weeks ago, and I had problems with migration.
I want some points of my application to be customized. Thus, I have a confsubodule that defines user settings and assigns reasonable defaults that will suit most cases.
This causes some of my model fields to look like this:
attachment = models.FilePathField(
path=conf.ATTACHMENTS_DIR, recursive=True)
template_file = models.FileField(
upload_to=conf.TEMPLATES_UPLOAD_DIR, blank=True)
prefix_subject = models.BooleanField(
default=True, verbose_name=_("prefix subject"),
help_text=_(
"Whether to prefix the subject with \"{}\" or not."
).format(conf.SUBJECT_PREFIX))
Unfortunately, in projects using this application, this leads to the fact that it django-admin makemigrationscreates a migration for it every time the parameter changes. Or even the first time they install the application for settings, the default value depends on the host system.
, . , .
prefix_subject . , help_text .
, / . ?
, , , . - .
, :
migrations.CreateModel(
name='MailStaticAttachment',
fields=[
('id', ...),
('filename', ...)
('mime_type', ...)
('attachment', models.FilePathField(path='/home/antoine/Workspace/django-mailing/static/mailing/attachments', recursive=True, verbose_name='file')),
],
options={...}
),
:
from ..conf import ATTACHMENTS_DIR
migrations.CreateModel(
name='MailStaticAttachment',
fields=[
('id', ...),
('filename', ...)
('mime_type', ...)
('attachment', models.FilePathField(path=ATTACHMENTS_DIR, recursive=True, verbose_name='file')),
],
options={...}
),
?
?
, Field.help_text, FilePathField.path FileField.upload_to SQL. - " ". , , , Field.default, Field.db_column CharField.max_length ? , , , , , .: P , , -.