Skip to content

Integrations: add created and updated fields to model #11067

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

Merged
merged 4 commits into from
Jan 29, 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
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
# Generated by Django 4.2.9 on 2024-01-25 17:46

import django.utils.timezone
import django_extensions.db.fields
from django.db import migrations


class Migration(migrations.Migration):
dependencies = [
("integrations", "0010_remove_old_jsonfields"),
]

operations = [
migrations.AlterModelOptions(
name="integration",
options={"get_latest_by": "modified"},
),
migrations.AddField(
model_name="integration",
name="created",
field=django_extensions.db.fields.CreationDateTimeField(
auto_now_add=True,
default=django.utils.timezone.now,
verbose_name="created",
null=True,
blank=True,
),
preserve_default=False,
),
migrations.AddField(
model_name="integration",
name="modified",
field=django_extensions.db.fields.ModificationDateTimeField(
auto_now=True,
verbose_name="modified",
null=True,
blank=True,
),
),
]
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Generated by Django 4.2.9 on 2024-01-29 19:16

from django.db import migrations
from django.utils import timezone


def forwards_func(apps, schema_editor):
Integration = apps.get_model("integrations", "Integration")
Integration.objects.filter(created=None).update(created=timezone.now())
Integration.objects.filter(modified=None).update(modified=timezone.now())


class Migration(migrations.Migration):
dependencies = [
("integrations", "0011_add_created_and_updated_fields"),
]

operations = [migrations.RunPython(forwards_func)]
23 changes: 17 additions & 6 deletions readthedocs/integrations/models.py
Original file line number Diff line number Diff line change
@@ -1,18 +1,16 @@
"""Integration models for external services."""

import json
import re
import uuid

from django.contrib.contenttypes.fields import (
GenericForeignKey,
GenericRelation,
)
from django.contrib.contenttypes.fields import GenericForeignKey, GenericRelation
from django.contrib.contenttypes.models import ContentType
from django.db import models, transaction
from django.utils.crypto import get_random_string
from django.utils.safestring import mark_safe
from django.utils.translation import gettext_lazy as _
from django_extensions.db.fields import CreationDateTimeField, ModificationDateTimeField
from django_extensions.db.models import TimeStampedModel
from pygments import highlight
from pygments.formatters import HtmlFormatter
from pygments.lexers import JsonLexer
Expand Down Expand Up @@ -262,7 +260,7 @@ def create(self, **kwargs):
return obj


class Integration(models.Model):
class Integration(TimeStampedModel):

"""Inbound webhook integration for projects."""

Expand All @@ -280,6 +278,19 @@ class Integration(models.Model):

INTEGRATIONS = WEBHOOK_INTEGRATIONS

# Overridden from TimeStampedModel just to allow null values.
# TODO: remove after deploy.
created = CreationDateTimeField(
_("created"),
null=True,
blank=True,
)
modified = ModificationDateTimeField(
_("modified"),
null=True,
blank=True,
)

project = models.ForeignKey(
Project,
related_name="integrations",
Expand Down