我难以理解信号是如何发挥作用的,但我走过了几页,但都没有帮助我了解情况。
我有两种模式,我谨发出信号,在父母保存记录时,将挽救儿童模式。 实际上,我要求儿童听取我向任何父母提出的申请,因为这一儿童,特别是一般的外国钥匙。
核心/模型。
from django.db import models
from django.contrib.auth.models import User
from django.contrib.contenttypes.models import ContentType
from django.contrib.contenttypes import generic
class Audit(models.Model):
## TODO: Document
# Polymorphic model using generic relation through DJANGO content type
operation = models.CharField(max_length=40)
operation_at = models.DateTimeField("Operation At", auto_now_add=True)
operation_by = models.ForeignKey(User, db_column="operation_by", related_name="%(app_label)s_%(class)s_y+")
content_type = models.ForeignKey(ContentType)
object_id = models.PositiveIntegerField()
content_object = generic.GenericForeignKey( content_type , object_id )
工作流程/模型
from django.db import models
from django.contrib.auth.models import User
from django.contrib.contenttypes.models import ContentType
from django.contrib.contenttypes import generic
from core.models import Audit
class Instances(models.Model):
## TODO: Document
## TODO: Replace id with XXXX-XXXX-XXXX-XXXX
# Re
INSTANCE_STATUS = (
( I , In Progress ),
( C , Cancelled ),
( D , Deleted ),
( P , Pending ),
( O , Completed )
)
id=models.CharField(max_length=200, primary_key=True)
status=models.CharField(max_length=1, choices=INSTANCE_STATUS, db_index=True)
audit_obj=generic.GenericRelation(Audit, editable=False, null=True, blank=True)
def save(self, *args, **kwargs):
# on new records generate a new uuid
if self.id is None or self.id.__len__() is 0:
import uuid
self.id=uuid.uuid4().__str__()
super(Instances, self).save(*args, **kwargs)
class Setup(models.Model):
## TODO: Document
# Polymorphic model using generic relation through DJANGO content type
content_type=models.ForeignKey(ContentType)
object_id=models.PositiveIntegerField()
content_object=generic.GenericForeignKey( content_type , object_id )
class Actions(models.Model):
ACTION_TYPE_CHOICES = (
( P , Python Script ),
( C , Class name ),
)
name=models.CharField(max_length=100)
action_type=models.CharField(max_length=1, choices=ACTION_TYPE_CHOICES)
class Tasks(models.Model):
name=models.CharField(max_length=100)
Instance=models.ForeignKey(Instances)
试图创建审计模式的听众,使我能够将其与事例模式联系起来,如果新记录在实例中插入,也会自动在审计中插入一个记录。 然后,我计划把这名听众与我的记忆中的若干模式联系起来。
任何想法,我如何能够做这样的事情?