예제 #1
0
파일: models.py 프로젝트: layashop/laya
 class Meta:
     indexes = [
         HashIndex(fields=["sent_by"]),
         HashIndex(fields=["status"]),
         HashIndex(fields=["created_at"]),
         BTreeIndex(fields=["created_at"]),
         BTreeIndex(fields=["status", "created_at"]),
     ]
예제 #2
0
 def test_deconstruction(self):
     index = HashIndex(fields=["title"], name="test_title_hash", fillfactor=80)
     path, args, kwargs = index.deconstruct()
     self.assertEqual(path, "django.contrib.postgres.indexes.HashIndex")
     self.assertEqual(args, ())
     self.assertEqual(
         kwargs, {"fields": ["title"], "name": "test_title_hash", "fillfactor": 80}
     )
예제 #3
0
파일: item.py 프로젝트: zz920/Dashboard
 class Meta:
     indexes = [
         models.Index(fields=['link']),
         models.Index(fields=['ean_code']),
         models.Index(fields=['name']),
         HashIndex(fields=['unit_id']),
         HashIndex(fields=['trace_id']),
     ]
     verbose_name = _('item')
     verbose_name_plural = _('items')
예제 #4
0
 class Meta:
     db_table = 'publications'
     indexes = [
         models.Index(fields=['id']),
         models.Index(fields=['n_citations']),
         HashIndex(fields=['doi']),
         HashIndex(fields=['semantic_scholar_id']),
         HashIndex(fields=['title']),
         HashIndex(fields=['venue']),
         HashIndex(fields=['volume']),
         models.Index(fields=['year']),
     ]
예제 #5
0
 def test_deconstruction(self):
     index = HashIndex(fields=['title'],
                       name='test_title_hash',
                       fillfactor=80)
     path, args, kwargs = index.deconstruct()
     self.assertEqual(path, 'django.contrib.postgres.indexes.HashIndex')
     self.assertEqual(args, ())
     self.assertEqual(kwargs, {
         'fields': ['title'],
         'name': 'test_title_hash',
         'fillfactor': 80
     })
예제 #6
0
 class Meta:
     indexes = [
         HashIndex(fields=["title"]),
         BTreeIndex(fields=["title", "state"]),
         BTreeIndex(fields=["title", "state", "delivery"]),
         HashIndex(fields=["state"]),
         HashIndex(fields=["delivery"]),
         HashIndex(fields=["title_slug"]),
         HashIndex(fields=["highlighted"]),
         GinIndex(fields=["tags"]),
         BTreeIndex(fields=["base_price"]),
         BTreeIndex(fields=["created_at"]),
     ]
예제 #7
0
 class Meta:
     verbose_name_plural = 'Addresses'
     ordering = ('locality', 'route', 'street_number')
     # unique_together = ('locality', 'route', 'street_number')
     indexes = [
         HashIndex(fields=['formatted']),
     ]
예제 #8
0
 class Meta:
     indexes = [HashIndex(fields=['etag'])]
     constraints = [
         models.UniqueConstraint(
             name='unique-etag-size',
             fields=['etag', 'size'],
         )
     ]
예제 #9
0
 def test_hash_parameters(self):
     index_name = 'integer_array_hash_fillfactor'
     index = HashIndex(fields=['field'], name=index_name, fillfactor=80)
     with connection.schema_editor() as editor:
         editor.add_index(CharFieldModel, index)
     constraints = self.get_constraints(CharFieldModel._meta.db_table)
     self.assertEqual(constraints[index_name]['type'], HashIndex.suffix)
     self.assertEqual(constraints[index_name]['options'], ['fillfactor=80'])
     with connection.schema_editor() as editor:
         editor.remove_index(CharFieldModel, index)
     self.assertNotIn(index_name, self.get_constraints(CharFieldModel._meta.db_table))
예제 #10
0
 def test_hash_index(self):
     # Ensure the table is there and doesn't have an index.
     self.assertNotIn('field', self.get_constraints(CharFieldModel._meta.db_table))
     # Add the index.
     index_name = 'char_field_model_field_hash'
     index = HashIndex(fields=['field'], name=index_name)
     with connection.schema_editor() as editor:
         editor.add_index(CharFieldModel, index)
     constraints = self.get_constraints(CharFieldModel._meta.db_table)
     # The index was added.
     self.assertEqual(constraints[index_name]['type'], HashIndex.suffix)
     # Drop the index.
     with connection.schema_editor() as editor:
         editor.remove_index(CharFieldModel, index)
     self.assertNotIn(index_name, self.get_constraints(CharFieldModel._meta.db_table))
예제 #11
0
 def test_deconstruction(self):
     index = HashIndex(fields=['title'], name='test_title_hash', fillfactor=80)
     path, args, kwargs = index.deconstruct()
     self.assertEqual(path, 'django.contrib.postgres.indexes.HashIndex')
     self.assertEqual(args, ())
     self.assertEqual(kwargs, {'fields': ['title'], 'name': 'test_title_hash', 'fillfactor': 80})
예제 #12
0
파일: version.py 프로젝트: dandi/dandi-api
 class Meta:
     unique_together = ['dandiset', 'version']
     indexes = [
         HashIndex(fields=['metadata']),
         HashIndex(fields=['name']),
     ]
예제 #13
0
 class Meta:
     indexes = [
         HashIndex(fields=('region',))
     ]
예제 #14
0
class Entry(models.Model):
    """
        Model is used to store data about user.
        This model creates a tree/trees and a DSU.
        All vertexes in one connected component describe one person.
    """
    key = models.CharField(max_length=255)
    value = models.CharField(max_length=255)
    report = models.ForeignKey(Report, on_delete=models.CASCADE)

    # Graph
    neighbours = models.ManyToManyField("self", blank=True)

    # DSU
    parent = models.ForeignKey("self",
                               on_delete=models.CASCADE,
                               blank=True,
                               null=True)
    rate = models.IntegerField(blank=True, default=0)

    indexes = (HashIndex(fields=('key', 'value')), )

    def get_parent(self):
        if self.parent == self:
            return self
        parent = self.parent.get_parent()
        self.parent = parent
        self.save()
        return parent

    def merge(self, other):
        a, b = self.get_parent(), other.get_parent()
        if a.rate < b.rate:
            a, b = b, a
        b.parent = a
        if a.rate == b.rate:
            a.rate += 1
        a.save()
        b.save()

    def save(self, *args, **kwargs):
        # Any changes here should be also applied in admin.py
        super(Entry, self).save(*args, **kwargs)
        if self._state.adding:
            self.parent = self
            self.save()
            if self.report.last is not None and self.report.last.get_parent(
            ) != self.get_parent():
                self.merge(self.report.last)
                self.neighbours.add(self.report.last)

            neighbours = Entry.objects.filter(key=self.key, value=self.value)
            for neighbour in neighbours.all():
                if self.get_parent() != neighbour.get_parent(
                ) and self != neighbour:
                    self.merge(neighbour)
                    self.neighbours.add(neighbour)

            self.report.last = self
            self.report.save()
            self.save()

    def __str__(self):
        return "{} : {}".format(self.key, self.value)
예제 #15
0
 class Meta:
     indexes = [HashIndex(fields=["timestamp"])]
예제 #16
0
 class Meta:
     indexes = [
         HashIndex(fields=('vehicle_vendor_model',))
     ]
예제 #17
0
 class Meta:
     indexes = [HashIndex(fields=["name"])]
예제 #18
0
 class Meta:
     indexes = [
         HashIndex(fields=['metadata']),
         HashIndex(fields=['name']),
     ]
예제 #19
0
 class Meta:
     indexes = [HashIndex(fields=["iso_code"])]
예제 #20
0
파일: asset.py 프로젝트: dandi/dandi-api
 class Meta:
     abstract = True
     indexes = [HashIndex(fields=['etag'])]
예제 #21
0
 class Meta:
     indexes = [HashIndex(fields=["slug"])]