class Meta: indexes = [ HashIndex(fields=["sent_by"]), HashIndex(fields=["status"]), HashIndex(fields=["created_at"]), BTreeIndex(fields=["created_at"]), BTreeIndex(fields=["status", "created_at"]), ]
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} )
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')
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']), ]
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 })
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"]), ]
class Meta: verbose_name_plural = 'Addresses' ordering = ('locality', 'route', 'street_number') # unique_together = ('locality', 'route', 'street_number') indexes = [ HashIndex(fields=['formatted']), ]
class Meta: indexes = [HashIndex(fields=['etag'])] constraints = [ models.UniqueConstraint( name='unique-etag-size', fields=['etag', 'size'], ) ]
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))
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))
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})
class Meta: unique_together = ['dandiset', 'version'] indexes = [ HashIndex(fields=['metadata']), HashIndex(fields=['name']), ]
class Meta: indexes = [ HashIndex(fields=('region',)) ]
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)
class Meta: indexes = [HashIndex(fields=["timestamp"])]
class Meta: indexes = [ HashIndex(fields=('vehicle_vendor_model',)) ]
class Meta: indexes = [HashIndex(fields=["name"])]
class Meta: indexes = [ HashIndex(fields=['metadata']), HashIndex(fields=['name']), ]
class Meta: indexes = [HashIndex(fields=["iso_code"])]
class Meta: abstract = True indexes = [HashIndex(fields=['etag'])]
class Meta: indexes = [HashIndex(fields=["slug"])]