Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Migrate to polymorphic manytomany field #3852

Merged
merged 3 commits into from
Oct 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading