Compare commits
1 Commits
pre-metada
...
main
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
e0af14e1b1 |
@@ -3,27 +3,12 @@ from django.utils import timezone
|
|||||||
from django.db.models import F
|
from django.db.models import F
|
||||||
|
|
||||||
from .base.admin import BaseModelAdmin
|
from .base.admin import BaseModelAdmin
|
||||||
from .models import Worker, Task, Trace, Metadata
|
from .models import Worker, Task, Trace
|
||||||
|
|
||||||
import os
|
import os
|
||||||
import asyncio
|
import asyncio
|
||||||
import humanize
|
import humanize
|
||||||
|
|
||||||
@admin.register( Metadata )
|
|
||||||
class MetadataAdmin( BaseModelAdmin ):
|
|
||||||
order = 3
|
|
||||||
list_display = 'name', 'model_type', 'target', 'expiration'
|
|
||||||
|
|
||||||
def target( self, obj ): return str(obj.model)
|
|
||||||
|
|
||||||
def expiration( self, obj ):
|
|
||||||
if obj.expiration_datetime: return humanize.naturaltime( obj.expiration_datetime )
|
|
||||||
return "Never"
|
|
||||||
expiration.admin_order_field = 'expiration_datetime'
|
|
||||||
|
|
||||||
def has_add_permission( self, request, obj = None ): return False
|
|
||||||
def has_change_permission( self, request, obj = None ): return False
|
|
||||||
|
|
||||||
@admin.register( Worker )
|
@admin.register( Worker )
|
||||||
class WorkerAdmin( BaseModelAdmin ):
|
class WorkerAdmin( BaseModelAdmin ):
|
||||||
order = 4
|
order = 4
|
||||||
|
|||||||
@@ -1,5 +1,4 @@
|
|||||||
from django.db import models
|
from django.db import models
|
||||||
from django.contrib.contenttypes.fields import GenericRelation
|
|
||||||
from django.core.exceptions import SynchronousOnlyOperation
|
from django.core.exceptions import SynchronousOnlyOperation
|
||||||
from asgiref.sync import sync_to_async
|
from asgiref.sync import sync_to_async
|
||||||
|
|
||||||
@@ -33,8 +32,7 @@ class AsyncronQuerySet( models.QuerySet ):
|
|||||||
|
|
||||||
class BaseModel( models.Model ):
|
class BaseModel( models.Model ):
|
||||||
objects = AsyncronQuerySet.as_manager()
|
objects = AsyncronQuerySet.as_manager()
|
||||||
metadata = GenericRelation("asyncron.Metadata", content_type_field = 'model_type', object_id_field = 'model_id')
|
|
||||||
|
|
||||||
async def eval_related( self, *fields ):
|
async def eval_related( self, *fields ):
|
||||||
if not fields:
|
if not fields:
|
||||||
fields = [ f.name for f in self._meta.fields if f.is_relation ]
|
fields = [ f.name for f in self._meta.fields if f.is_relation ]
|
||||||
|
|||||||
@@ -0,0 +1,20 @@
|
|||||||
|
# Generated by Django 6.0.6 on 2026-07-25 15:34
|
||||||
|
|
||||||
|
from django.db import migrations
|
||||||
|
|
||||||
|
|
||||||
|
class Migration(migrations.Migration):
|
||||||
|
|
||||||
|
dependencies = [
|
||||||
|
('asyncron', '0005_rename_last_crowning_attempt_worker_last_activity'),
|
||||||
|
]
|
||||||
|
|
||||||
|
operations = [
|
||||||
|
migrations.RemoveIndex(
|
||||||
|
model_name='metadata',
|
||||||
|
name='asyncron_me_model_t_d92186_idx',
|
||||||
|
),
|
||||||
|
migrations.DeleteModel(
|
||||||
|
name='Metadata',
|
||||||
|
),
|
||||||
|
]
|
||||||
@@ -241,30 +241,3 @@ class Trace( BaseModel ):
|
|||||||
assert hasattr(self, 'commit_on_new_print_task'), "trace.print needs to be called while a trace.commit_on_new_print task is active!"
|
assert hasattr(self, 'commit_on_new_print_task'), "trace.print needs to be called while a trace.commit_on_new_print task is active!"
|
||||||
self.stdout += sep.join( str(i) for i in args ) + end
|
self.stdout += sep.join( str(i) for i in args ) + end
|
||||||
if flush: self.new_print.set()
|
if flush: self.new_print.set()
|
||||||
|
|
||||||
|
|
||||||
#https://docs.djangoproject.com/en/5.1/ref/contrib/contenttypes/
|
|
||||||
from django.contrib.contenttypes.fields import GenericForeignKey
|
|
||||||
from django.contrib.contenttypes.models import ContentType
|
|
||||||
class Metadata( BaseModel ):
|
|
||||||
model_type = models.ForeignKey( ContentType, on_delete = models.CASCADE )
|
|
||||||
model_id = models.PositiveIntegerField()
|
|
||||||
model = GenericForeignKey("model_type", "model_id")
|
|
||||||
|
|
||||||
name = models.CharField( max_length = 256 )
|
|
||||||
data = models.JSONField( null = True, blank = True )
|
|
||||||
expiration_datetime = models.DateTimeField( null = True, blank = True )
|
|
||||||
|
|
||||||
@property
|
|
||||||
def is_expired( self ):
|
|
||||||
if self.expiration_datetime: return self.expiration_datetime < timezone.now()
|
|
||||||
return False
|
|
||||||
|
|
||||||
|
|
||||||
def __str__(self): return self.name
|
|
||||||
|
|
||||||
class Meta:
|
|
||||||
indexes = [
|
|
||||||
models.Index(fields=["model_type", "model_id"]),
|
|
||||||
]
|
|
||||||
verbose_name = verbose_name_plural = 'Metadata'
|
|
||||||
|
|||||||
Reference in New Issue
Block a user