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

feat: poll in django admin, pipeline FK, migrations #663

Closed
wants to merge 1 commit into from
Closed
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
37 changes: 35 additions & 2 deletions backend/apps/api/v1/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
ReorderColumnsForm,
ReorderTablesForm,
TableInlineForm,
PollInlineForm,
UpdateInlineForm,
)
from backend.apps.api.v1.models import (
Expand All @@ -53,6 +54,7 @@
ObservationLevel,
Organization,
Pipeline,
Poll,
QualityCheck,
RawDataSource,
Status,
Expand Down Expand Up @@ -229,6 +231,19 @@ def datetime_ranges(self, cov):
"""Show datetime ranges in coverage inline"""
return [str(dt) for dt in cov.datetime_ranges.all()]

class PollInline(admin.StackedInline):
model = Poll
form = PollInlineForm
extra = 0
fields = [
"id",
"entity",
"frequency",
"latest",
]
autocomplete_fields = [
"entity",
]

class UpdateInline(admin.StackedInline):
model = Update
Expand Down Expand Up @@ -699,15 +714,15 @@ class RawDataSourceAdmin(TabbedTranslationAdmin):
"languages",
"area_ip_address_required",
]
inlines = [CoverageInline]
inlines = [CoverageInline, PollInline]


class InformationRequestAdmin(TabbedTranslationAdmin):
list_display = ["__str__", "dataset", "created_at", "updated_at"]
search_fields = ["__str__", "dataset__name"]
readonly_fields = ["id", "created_at", "updated_at"]
autocomplete_fields = ["dataset"]
inlines = [CoverageInline, ObservationLevelInline]
inlines = [CoverageInline, ObservationLevelInline, PollInline]


class CoverageTypeAdminFilter(admin.SimpleListFilter):
Expand Down Expand Up @@ -830,6 +845,23 @@ class LanguageAdmin(TabbedTranslationAdmin):
"slug",
]

class PollAdmin(admin.ModelAdmin):
readonly_fields = [
"id",
]
list_display = [
"__str__",
]
search_fields = [
"entity",
"raw_data_source",
"information_request",
]
autocomplete_fields = [
"entity",
"raw_data_source",
"information_request",
]

class UpdateAdmin(admin.ModelAdmin):
readonly_fields = [
Expand Down Expand Up @@ -1014,6 +1046,7 @@ class QualityCheckAdmin(TabbedTranslationAdmin):
admin.site.register(ObservationLevel, ObservationLevelAdmin)
admin.site.register(Organization, OrganizationAdmin)
admin.site.register(Pipeline)
admin.site.register(Poll, PollAdmin)
admin.site.register(RawDataSource, RawDataSourceAdmin)
admin.site.register(Status, StatusAdmin)
admin.site.register(Table, TableAdmin)
Expand Down
1 change: 1 addition & 0 deletions backend/apps/api/v1/forms/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
CoverageInlineForm,
ObservationLevelInlineForm,
TableInlineForm,
PollInlineForm,
UpdateInlineForm,
)
from backend.apps.api.v1.forms.reorder_columns_form import ReorderColumnsForm # noqa: F401
Expand Down
6 changes: 6 additions & 0 deletions backend/apps/api/v1/forms/admin_form.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
Coverage,
ObservationLevel,
Table,
Poll,
Update,
)

Expand Down Expand Up @@ -106,6 +107,11 @@ class Meta(UUIDHiddenIdForm.Meta):
]


class PollInlineForm(UUIDHiddenIdForm):
class Meta(UUIDHiddenIdForm.Meta):
model = Poll
fields = "__all__"

class UpdateInlineForm(UUIDHiddenIdForm):
class Meta(UUIDHiddenIdForm.Meta):
model = Update
Expand Down
19 changes: 19 additions & 0 deletions backend/apps/api/v1/migrations/0037_poll_pipeline.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# Generated by Django 4.2.13 on 2024-08-21 05:40

from django.db import migrations, models
import django.db.models.deletion


class Migration(migrations.Migration):

dependencies = [
('v1', '0036_datetimerange_unit'),
]

operations = [
migrations.AddField(
model_name='poll',
name='pipeline',
field=models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.PROTECT, related_name='polls', to='v1.pipeline'),
),
]
7 changes: 7 additions & 0 deletions backend/apps/api/v1/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -742,6 +742,13 @@ class Poll(BaseModel):
)
frequency = models.IntegerField(blank=True, null=True)
latest = models.DateTimeField(blank=True, null=True)
pipeline = models.ForeignKey(
"Pipeline",
blank=True,
null=True,
on_delete=models.PROTECT,
related_name="polls"
)
raw_data_source = models.ForeignKey(
"RawDataSource",
blank=True,
Expand Down
Loading