Skip to content
This repository has been archived by the owner on Feb 1, 2024. It is now read-only.

Commit

Permalink
Add Source model
Browse files Browse the repository at this point in the history
Starts the process of adding support for single-item submissions by introducing
a model that can connect a `FacilityListItem` to a `Contributor` without needing
a `FacilityList`

`FacilityListItem.source` is nullable for now to make the migration backward
compatible.
  • Loading branch information
jwalgran committed Oct 2, 2019
1 parent 23a9d02 commit 3742057
Show file tree
Hide file tree
Showing 2 changed files with 93 additions and 0 deletions.
33 changes: 33 additions & 0 deletions src/django/api/migrations/0035_add_source_20190926_2048.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# Generated by Django 2.2.3 on 2019-10-01 15:31

from django.db import migrations, models
import django.db.models.deletion


class Migration(migrations.Migration):

dependencies = [
('api', '0034_facilitylocation'),
]

operations = [
migrations.CreateModel(
name='Source',
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('source_type', models.CharField(choices=[('LIST', 'LIST'), ('SINGLE', 'SINGLE')], help_text='Did the the facility data arrive in a list or a single item', max_length=6)),
('is_active', models.BooleanField(default=True, help_text='True if items from the source should be shown as being associated with the contributor')),
('is_public', models.BooleanField(default=True, help_text='True if the public can see factories from this list are associated with the contributor.')),
('create', models.BooleanField(default=True, help_text='Should a facility or facility match be created from the facility data')),
('created_at', models.DateTimeField(auto_now_add=True)),
('updated_at', models.DateTimeField(auto_now=True)),
('contributor', models.ForeignKey(help_text='The contributor who submitted the facility data', null=True, on_delete=django.db.models.deletion.SET_NULL, to='api.Contributor')),
('facility_list', models.OneToOneField(help_text='The related list if the type of the source is LIST.', null=True, on_delete=django.db.models.deletion.PROTECT, to='api.FacilityList')),
],
),
migrations.AddField(
model_name='facilitylistitem',
name='source',
field=models.ForeignKey(blank=True, help_text='The source from which this item was created.', null=True, on_delete=django.db.models.deletion.PROTECT, to='api.Source'),
),
]
60 changes: 60 additions & 0 deletions src/django/api/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,59 @@ def did_register_and_confirm_email(self):
return True


class Source(models.Model):
LIST = 'LIST'
SINGLE = 'SINGLE'

SOURCE_TYPE_CHOICES = (
(LIST, LIST),
(SINGLE, SINGLE),
)

contributor = models.ForeignKey(
'Contributor',
null=True,
on_delete=models.SET_NULL,
help_text='The contributor who submitted the facility data'
)
source_type = models.CharField(
null=False,
max_length=6,
choices=SOURCE_TYPE_CHOICES,
help_text='Did the the facility data arrive in a list or a single item'
)
facility_list = models.OneToOneField(
'FacilityList',
null=True,
on_delete=models.PROTECT,
help_text='The related list if the type of the source is LIST.'
)
is_active = models.BooleanField(
null=False,
default=True,
help_text=('True if items from the source should be shown as being '
'associated with the contributor')
)
is_public = models.BooleanField(
null=False,
default=True,
help_text=('True if the public can see factories from this list '
'are associated with the contributor.')
)
create = models.BooleanField(
null=False,
default=True,
help_text=('Should a facility or facility match be created from the '
'facility data')
)
created_at = models.DateTimeField(auto_now_add=True)
updated_at = models.DateTimeField(auto_now=True)

def __str__(self):
return '{0} ({1})'.format(
self.contributor.name, self.id)


class FacilityList(models.Model):
"""
Metadata for an uploaded list of facilities.
Expand Down Expand Up @@ -320,6 +373,13 @@ class Meta:
'FacilityList',
on_delete=models.CASCADE,
help_text='The list that this line item is a part of.')
source = models.ForeignKey(
'Source',
null=True,
blank=True,
on_delete=models.PROTECT,
help_text='The source from which this item was created.'
)
row_index = models.IntegerField(
null=False,
editable=False,
Expand Down

0 comments on commit 3742057

Please sign in to comment.