12 changed files with 221 additions and 4 deletions
-
1apps/hadis/admin/__init__.py
-
29apps/hadis/admin/version.py
-
63apps/hadis/docs.py
-
26apps/hadis/migrations/0086_alter_opinionstatus_options_and_more.py
-
44apps/hadis/migrations/0087_contentrelease.py
-
1apps/hadis/models/__init__.py
-
13apps/hadis/models/version.py
-
1apps/hadis/serializers/__init__.py
-
16apps/hadis/serializers/version.py
-
2apps/hadis/urls.py
-
1apps/hadis/views/hadis.py
-
20apps/hadis/views/version.py
@ -0,0 +1,29 @@ |
|||||
|
from django.contrib import admin |
||||
|
from django.utils.translation import gettext_lazy as _ |
||||
|
from unfold.admin import ModelAdmin |
||||
|
|
||||
|
from utils.admin import project_admin_site |
||||
|
from ..models import ContentRelease |
||||
|
|
||||
|
|
||||
|
class ContentReleaseAdmin(ModelAdmin): |
||||
|
"""Admin for ContentRelease model""" |
||||
|
list_display = ('version_name', 'published_at', 'is_active') |
||||
|
list_filter = ('is_active', 'published_at') |
||||
|
search_fields = ('version_name', 'description') |
||||
|
readonly_fields = ('published_at',) |
||||
|
ordering = ('-published_at',) |
||||
|
|
||||
|
fieldsets = ( |
||||
|
(None, { |
||||
|
'fields': ('version_name', 'description', 'is_active') |
||||
|
}), |
||||
|
(_('Timestamps'), { |
||||
|
'fields': ('published_at',), |
||||
|
'classes': ('collapse',) |
||||
|
}), |
||||
|
) |
||||
|
|
||||
|
|
||||
|
# Register model with the custom admin site |
||||
|
project_admin_site.register(ContentRelease, ContentReleaseAdmin) |
||||
@ -0,0 +1,26 @@ |
|||||
|
# Generated by Django 4.2.27 on 2025-12-27 09:42 |
||||
|
|
||||
|
from django.db import migrations |
||||
|
|
||||
|
|
||||
|
class Migration(migrations.Migration): |
||||
|
dependencies = [ |
||||
|
("hadis", "0085_hadistransmitter_hadis_hadis_hadis_i_d04e3a_idx_and_more"), |
||||
|
] |
||||
|
|
||||
|
operations = [ |
||||
|
migrations.AlterModelOptions( |
||||
|
name="opinionstatus", |
||||
|
options={ |
||||
|
"verbose_name": "Opinion Status", |
||||
|
"verbose_name_plural": "Opinion Statuses", |
||||
|
}, |
||||
|
), |
||||
|
migrations.AlterModelOptions( |
||||
|
name="transmitterreliability", |
||||
|
options={ |
||||
|
"verbose_name": "Transmitter Reliability", |
||||
|
"verbose_name_plural": "Transmitter Reliabilities", |
||||
|
}, |
||||
|
), |
||||
|
] |
||||
@ -0,0 +1,44 @@ |
|||||
|
# Generated by Django 4.2.27 on 2025-12-27 10:32 |
||||
|
|
||||
|
from django.db import migrations, models |
||||
|
|
||||
|
|
||||
|
class Migration(migrations.Migration): |
||||
|
dependencies = [ |
||||
|
("hadis", "0086_alter_opinionstatus_options_and_more"), |
||||
|
] |
||||
|
|
||||
|
operations = [ |
||||
|
migrations.CreateModel( |
||||
|
name="ContentRelease", |
||||
|
fields=[ |
||||
|
( |
||||
|
"id", |
||||
|
models.BigAutoField( |
||||
|
auto_created=True, |
||||
|
primary_key=True, |
||||
|
serialize=False, |
||||
|
verbose_name="ID", |
||||
|
), |
||||
|
), |
||||
|
( |
||||
|
"version_name", |
||||
|
models.CharField(max_length=50, verbose_name="Version Name"), |
||||
|
), |
||||
|
( |
||||
|
"published_at", |
||||
|
models.DateTimeField( |
||||
|
auto_now_add=True, verbose_name="Published Date" |
||||
|
), |
||||
|
), |
||||
|
( |
||||
|
"description", |
||||
|
models.TextField(blank=True, verbose_name="Release Description"), |
||||
|
), |
||||
|
("is_active", models.BooleanField(default=True, verbose_name="Active")), |
||||
|
], |
||||
|
options={ |
||||
|
"ordering": ["-published_at"], |
||||
|
}, |
||||
|
), |
||||
|
] |
||||
@ -0,0 +1,13 @@ |
|||||
|
from django.db import models |
||||
|
from django.utils.translation import gettext_lazy as _ |
||||
|
|
||||
|
class ContentRelease(models.Model): |
||||
|
version_name = models.CharField(max_length=50, verbose_name=_('Version Name')) # e.g., "v1.2 - Muharram Update" |
||||
|
published_at = models.DateTimeField(auto_now_add=True, verbose_name=_("Published Date")) |
||||
|
description = models.TextField(blank=True, verbose_name=_("Release Description")) |
||||
|
|
||||
|
# Optional: is_active to easily rollback updates if something breaks |
||||
|
is_active = models.BooleanField(default=True, verbose_name=_("Active")) |
||||
|
|
||||
|
class Meta: |
||||
|
ordering = ['-published_at'] |
||||
@ -1,2 +1,3 @@ |
|||||
from .category import * |
from .category import * |
||||
from .hadis import * |
from .hadis import * |
||||
|
from .version import * |
||||
@ -0,0 +1,16 @@ |
|||||
|
from rest_framework import serializers |
||||
|
from ..models import ContentRelease |
||||
|
|
||||
|
|
||||
|
class ContentReleaseSyncSerializer(serializers.ModelSerializer): |
||||
|
"""Serializer for syncing content release data for offline mode""" |
||||
|
|
||||
|
class Meta: |
||||
|
model = ContentRelease |
||||
|
fields = [ |
||||
|
'id', |
||||
|
'version_name', |
||||
|
'published_at', |
||||
|
'description', |
||||
|
'is_active' |
||||
|
] |
||||
@ -0,0 +1,20 @@ |
|||||
|
from rest_framework.generics import RetrieveAPIView |
||||
|
from rest_framework.response import Response |
||||
|
|
||||
|
from ..models import ContentRelease |
||||
|
from ..serializers import ContentReleaseSyncSerializer |
||||
|
from ..docs import content_release_sync_swagger |
||||
|
|
||||
|
|
||||
|
class ContentReleaseSyncView(RetrieveAPIView): |
||||
|
""" |
||||
|
API view to get the latest content release for offline mode sync |
||||
|
""" |
||||
|
serializer_class = ContentReleaseSyncSerializer |
||||
|
|
||||
|
@content_release_sync_swagger |
||||
|
def get(self, request, *args, **kwargs): |
||||
|
return self.retrieve(request, *args, **kwargs) |
||||
|
|
||||
|
def get_object(self): |
||||
|
return ContentRelease.objects.filter(is_active=True).order_by('-published_at').first() |
||||
Write
Preview
Loading…
Cancel
Save
Reference in new issue