Skip to content

Commit

Permalink
Merge pull request #3852 from allegro/migrate-to-polymorphic-many-to-…
Browse files Browse the repository at this point in the history
…many-field

Migrate to polymorphic manytomany field
  • Loading branch information
hipek8 authored Oct 7, 2024
2 parents 7337de1 + 4d0c405 commit dc77d61
Show file tree
Hide file tree
Showing 5 changed files with 47 additions and 5 deletions.
4 changes: 1 addition & 3 deletions src/ralph/dashboards/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -299,9 +299,7 @@ def _default_aggregation_handler(
)

def build_queryset(self, annotated=True, queryset=None):
model = self.model.model_class()
model_manager = model._default_manager
queryset = queryset or model_manager.all()
queryset = queryset or self.model.model_class().objects.all()

grouping_label = GroupingLabel(connection, self.params['labels'])
if annotated:
Expand Down
21 changes: 21 additions & 0 deletions src/ralph/operations/migrations/0013_auto_20241002_1122.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# -*- coding: utf-8 -*-
# Generated by Django 1.11.8 on 2024-10-02 11:22
from __future__ import unicode_literals

from django.db import migrations
import ralph.lib.polymorphic.fields


class Migration(migrations.Migration):

dependencies = [
('operations', '0012_auto_20211206_1347'),
]

operations = [
migrations.AlterField(
model_name='operation',
name='base_objects',
field=ralph.lib.polymorphic.fields.PolymorphicManyToManyField(blank=True, related_name='operations', to='assets.BaseObject', verbose_name='objects'),
),
]
3 changes: 2 additions & 1 deletion src/ralph/operations/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
NamedMixin,
TaggableMixin
)
from ralph.lib.polymorphic.fields import PolymorphicManyToManyField


class OperationStatus(AdminAbsoluteUrlMixin, NamedMixin, models.Model):
Expand Down Expand Up @@ -96,7 +97,7 @@ class Operation(AdminAbsoluteUrlMixin, TaggableMixin, models.Model):
resolved_date = models.DateTimeField(
null=True, blank=True, verbose_name=_('resolved date'),
)
base_objects = models.ManyToManyField(
base_objects = PolymorphicManyToManyField(
BaseObject, related_name='operations', verbose_name=_('objects'),
blank=True,
)
Expand Down
21 changes: 21 additions & 0 deletions src/ralph/supports/migrations/0010_auto_20241002_1122.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# -*- coding: utf-8 -*-
# Generated by Django 1.11.8 on 2024-10-02 11:22
from __future__ import unicode_literals

from django.db import migrations
import ralph.lib.polymorphic.fields


class Migration(migrations.Migration):

dependencies = [
('supports', '0009_auto_20240506_1633'),
]

operations = [
migrations.AlterField(
model_name='support',
name='base_objects',
field=ralph.lib.polymorphic.fields.PolymorphicManyToManyField(related_name='_support_base_objects_+', through='supports.BaseObjectsSupport', to='assets.BaseObject'),
),
]
3 changes: 2 additions & 1 deletion src/ralph/supports/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
NamedMixin,
PriceMixin
)
from ralph.lib.polymorphic.fields import PolymorphicManyToManyField
from ralph.lib.polymorphic.models import PolymorphicQuerySet


Expand Down Expand Up @@ -131,7 +132,7 @@ class Support(
default=None,
null=True,
)
base_objects = models.ManyToManyField(
base_objects = PolymorphicManyToManyField(
BaseObject,
related_name='+',
through='BaseObjectsSupport',
Expand Down

0 comments on commit dc77d61

Please sign in to comment.