src/iconolab/models.py
changeset 592 a87ffe8e08e5
parent 566 238d1023c776
equal deleted inserted replaced
591:30644b6ac4ce 592:a87ffe8e08e5
   150 class ItemMetadata(models.Model):
   150 class ItemMetadata(models.Model):
   151     """
   151     """
   152         Metadata object for the item class.
   152         Metadata object for the item class.
   153     """
   153     """
   154 
   154 
   155     item = models.OneToOneField('Item', related_name='metadatas', on_delete=models.PROTECT)
   155     item = models.OneToOneField('Item', related_name='metadatas', on_delete=models.CASCADE)
   156 
   156 
   157     natural_key = models.CharField(max_length=1024, default="", unique=True)
   157     natural_key = models.CharField(max_length=1024, default="", unique=True)
   158 
   158 
   159     """
   159     """
   160     JSON field integration
   160     JSON field integration
   201     image_guid = models.UUIDField(default=uuid.uuid4, editable=False)
   201     image_guid = models.UUIDField(default=uuid.uuid4, editable=False)
   202     name = models.CharField(max_length=200)
   202     name = models.CharField(max_length=200)
   203     media = models.ImageField(upload_to='uploads/',
   203     media = models.ImageField(upload_to='uploads/',
   204                               height_field='height', width_field='width')
   204                               height_field='height', width_field='width')
   205     item = models.ForeignKey(
   205     item = models.ForeignKey(
   206         'Item', related_name='images', null=True, blank=True, on_delete=models.PROTECT)
   206         'Item', related_name='images', null=True, blank=True, on_delete=models.CASCADE)
   207     height = models.IntegerField(null=False, blank=False)
   207     height = models.IntegerField(null=False, blank=False)
   208     width = models.IntegerField(null=False, blank=False)
   208     width = models.IntegerField(null=False, blank=False)
   209     created = models.DateTimeField(auto_now_add=True, null=True)
   209     created = models.DateTimeField(auto_now_add=True, null=True)
   210 
   210 
   211     def __str__(self):
   211     def __str__(self):
   238     """
   238     """
   239         Stats objects for a given image, keep count of several values to be
   239         Stats objects for a given image, keep count of several values to be
   240         displayed in image and item pages
   240         displayed in image and item pages
   241     """
   241     """
   242     image = models.OneToOneField(
   242     image = models.OneToOneField(
   243         'Image', related_name='stats', blank=False, null=False, on_delete=models.PROTECT)
   243         'Image', related_name='stats', blank=False, null=False, on_delete=models.CASCADE)
   244     views_count = models.IntegerField(blank=True, null=True, default=0)
   244     views_count = models.IntegerField(blank=True, null=True, default=0)
   245     annotations_count = models.IntegerField(blank=True, null=True, default=0)
   245     annotations_count = models.IntegerField(blank=True, null=True, default=0)
   246     submitted_revisions_count = models.IntegerField(
   246     submitted_revisions_count = models.IntegerField(
   247         blank=True, null=True, default=0)
   247         blank=True, null=True, default=0)
   248     comments_count = models.IntegerField(blank=True, null=True, default=0)
   248     comments_count = models.IntegerField(blank=True, null=True, default=0)
   439     )
   439     )
   440     annotation_guid = models.UUIDField(default=uuid.uuid4, editable=False)
   440     annotation_guid = models.UUIDField(default=uuid.uuid4, editable=False)
   441     image = models.ForeignKey(
   441     image = models.ForeignKey(
   442         'Image', related_name='annotations', on_delete=models.CASCADE)
   442         'Image', related_name='annotations', on_delete=models.CASCADE)
   443     source_revision = models.ForeignKey(
   443     source_revision = models.ForeignKey(
   444         'AnnotationRevision', related_name='source_related_annotation', blank=True, null=True, on_delete=models.PROTECT)
   444         'AnnotationRevision', related_name='source_related_annotation', blank=True, null=True, on_delete=models.SET_NULL)
   445     current_revision = models.OneToOneField(
   445     current_revision = models.OneToOneField(
   446         'AnnotationRevision', related_name='current_for_annotation', blank=True, null=True, on_delete=models.PROTECT)
   446         'AnnotationRevision', related_name='current_for_annotation', blank=True, null=True, on_delete=models.SET_NULL)
   447     author = models.ForeignKey(User, null=True, on_delete=models.PROTECT)
   447     author = models.ForeignKey(User, null=True, on_delete=models.PROTECT)
   448     created = models.DateTimeField(auto_now_add=True, null=True)
   448     created = models.DateTimeField(auto_now_add=True, null=True)
   449     comments = GenericRelation(
   449     comments = GenericRelation(
   450         'IconolabComment', content_type_field='content_type_id', object_id_field='object_pk')
   450         'IconolabComment', content_type_field='content_type_id', object_id_field='object_pk')
   451     validation_state = models.IntegerField(
   451     validation_state = models.IntegerField(
   572     """
   572     """
   573         Stats objects for a given annotation, keep count of several values to be
   573         Stats objects for a given annotation, keep count of several values to be
   574         displayed in annotation pages
   574         displayed in annotation pages
   575     """
   575     """
   576     annotation = models.OneToOneField(
   576     annotation = models.OneToOneField(
   577         'Annotation', related_name='stats', blank=False, null=False, on_delete=models.PROTECT)
   577         'Annotation', related_name='stats', blank=False, null=False, on_delete=models.CASCADE)
   578     submitted_revisions_count = models.IntegerField(
   578     submitted_revisions_count = models.IntegerField(
   579         blank=True, null=True, default=1)
   579         blank=True, null=True, default=1)
   580     awaiting_revisions_count = models.IntegerField(
   580     awaiting_revisions_count = models.IntegerField(
   581         blank=True, null=True, default=0)
   581         blank=True, null=True, default=0)
   582     accepted_revisions_count = models.IntegerField(
   582     accepted_revisions_count = models.IntegerField(
   716         (STUDIED, 'studied'),
   716         (STUDIED, 'studied'),
   717     )
   717     )
   718 
   718 
   719     revision_guid = models.UUIDField(default=uuid.uuid4)
   719     revision_guid = models.UUIDField(default=uuid.uuid4)
   720     annotation = models.ForeignKey(
   720     annotation = models.ForeignKey(
   721         'Annotation', related_name='revisions', null=False, blank=False, on_delete=models.PROTECT)
   721         'Annotation', related_name='revisions', null=False, blank=False, on_delete=models.CASCADE)
   722     parent_revision = models.ForeignKey(
   722     parent_revision = models.ForeignKey(
   723         'AnnotationRevision', related_name='child_revisions', blank=True, null=True, on_delete=models.PROTECT)
   723         'AnnotationRevision', related_name='child_revisions', blank=True, null=True, on_delete=models.SET_NULL)
   724     merge_parent_revision = models.ForeignKey(
   724     merge_parent_revision = models.ForeignKey(
   725         'AnnotationRevision', related_name='child_revisions_merge', blank=True, null=True, on_delete=models.PROTECT)
   725         'AnnotationRevision', related_name='child_revisions_merge', blank=True, null=True, on_delete=models.SET_NULL)
   726     author = models.ForeignKey(User, null=True, on_delete=models.PROTECT)
   726     author = models.ForeignKey(User, null=True, on_delete=models.PROTECT)
   727     title = models.CharField(max_length=255)
   727     title = models.CharField(max_length=255)
   728     description = models.TextField(null=True)
   728     description = models.TextField(null=True)
   729     fragment = models.TextField()
   729     fragment = models.TextField()
   730     tags = models.ManyToManyField(
   730     tags = models.ManyToManyField(