Skip to content

Commit

Permalink
Merge pull request #10503 from cslzchen/feature/cedar-integration
Browse files Browse the repository at this point in the history
[ENG-4853] Create `CedarMetadataRecord` model to connect metadata to OSF objects
  • Loading branch information
adlius authored Dec 14, 2023
2 parents fb629a0 + 75d83e1 commit 6fd45ce
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 0 deletions.
34 changes: 34 additions & 0 deletions osf/migrations/0018_cedarmetadatarecord.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
# Generated by Django 3.2.17 on 2023-12-14 17:06

from django.db import migrations, models
import django.db.models.deletion
import django_extensions.db.fields
import osf.models.base
import osf.utils.datetime_aware_jsonfield


class Migration(migrations.Migration):

dependencies = [
('osf', '0017_cedarmetadatatemplate'),
]

operations = [
migrations.CreateModel(
name='CedarMetadataRecord',
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')),
('_id', models.CharField(db_index=True, default=osf.models.base.generate_object_id, max_length=24, unique=True)),
('metadata', osf.utils.datetime_aware_jsonfield.DateTimeAwareJSONField(default=dict, encoder=osf.utils.datetime_aware_jsonfield.DateTimeAwareJSONEncoder)),
('is_published', models.BooleanField(default=False)),
('guid', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='osf.guid')),
('template', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='osf.cedarmetadatatemplate')),
],
options={
'unique_together': {('guid', 'template')},
},
bases=(models.Model, osf.models.base.QuerySetExplainMixin),
),
]
14 changes: 14 additions & 0 deletions osf/models/cedar_metadata.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,17 @@ class Meta:

def __unicode__(self):
return f'(name=[{self.schema_name}], version=[{self.template_version}], id=[{self.cedar_id}])'


class CedarMetadataRecord(ObjectIDMixin, BaseModel):

guid = models.ForeignKey('Guid', on_delete=models.CASCADE)
template = models.ForeignKey('CedarMetadataTemplate', on_delete=models.CASCADE)
metadata = DateTimeAwareJSONField(default=dict)
is_published = models.BooleanField(default=False)

class Meta:
unique_together = ('guid', 'template')

def __unicode__(self):
return f'(guid=[{self.guid._id}], template=[{self.template._id}])'

0 comments on commit 6fd45ce

Please sign in to comment.