我想从两个迁移表中获取一个新表:
在“迁移”文件夹中,创建以下表:
migrations.CreateModel(
name='GeneratedReport',
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('created', django_extensions.db.fields.CreationDateTimeField(auto_now_add=True, verbose_name='created')),
('modified', django_extensions.db.fields.ModificationDateTimeField(auto_now=True, verbose_name='modified')),
('print_date', models.DateTimeField(blank=True, null=True)),
('s3_url', models.CharField(blank=True, max_length=200, null=True)),
('error', models.CharField(blank=True, max_length=600, null=True)),
('size', models.FloatField(blank=True, null=True)),
],
options={
'ordering': ('-modified', '-created'),
'get_latest_by': 'modified',
'abstract': False,
},
),
migrations.CreateModel(
name='Subscriber',
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('created', django_extensions.db.fields.CreationDateTimeField(auto_now_add=True, verbose_name='created')),
('modified', django_extensions.db.fields.ModificationDateTimeField(auto_now=True, verbose_name='modified')),
('userid', models.IntegerField(unique=True)),
('name', models.CharField(blank=True, max_length=100, null=True)),
('email', models.EmailField(max_length=100)),
('contribution', models.IntegerField()),
('signupdate', models.DateTimeField()),
('user_lang', models.CharField(blank=True, choices=[('en', 'English'), ('fr', 'French'), ('es', 'Spanish'), ('jp', 'Japanese')], max_length=3, null=True)),
('subscribed', models.BooleanField(default=True)),
('_weather_unit', models.CharField(blank=True, choices=[('us', 'Imperial'), ('si', 'SI'), (None, 'Automatic')], max_length=3, null=True)),
],
options={
'ordering': ('-modified', '-created'),
'get_latest_by': 'modified',
'abstract': False,
},
),
在models.py中:
class Subscriber(TimeStampedModel):
userid = models.IntegerField(unique=True)
name = models.CharField(max_length=100, null=True, blank=True)
email = models.EmailField(max_length=100)
contribution = models.IntegerField()
signupdate = models.DateTimeField()
user_lang = models.CharField(max_length=3, null=True, blank=True, choices=LANGUAGE_CHOICES)
subscribed = models.BooleanField(default=True)
_weather_unit = models.CharField(max_length=3, null=True, blank=True, choices=WEATHER_UNIT_CHOICES)
class GeneratedReport(TimeStampedModel):
report = models.ForeignKey(ReportType, on_delete=models.PROTECT)
print_date = models.DateTimeField(null=True, blank=True)
s3_url = models.CharField(max_length=200, null=True, blank=True)
error = models.CharField(max_length=600, null=True, blank=True)
size = models.FloatField(null=True, blank=True)
现在,我想获得一个包含以下字段的新表:
user
month
year
s3_link
我不太确定应该在migrations
文件夹和models.py
脚本中做什么。我必须创建一个新模型吗?以及如何准确地在models.py和使用Django的迁移之间建立连接。
最终目标是使用给定的用户名,使用HTTP方法获取每个s3_link