“Django Wht Post Save Sign” Ответ

Django Wht Post Save Sign

default_app_config = 'activity.apps.ActivityAppConfig'
Relieved Ratel

Django Wht Post Save Sign

post_save.connect(create_activity_item, sender=Status,
                  dispatch_uid="create_activity_item")
Relieved Ratel

Django Wht Post Save Sign

class MyModel(models.Model):
    """ MyModel fields go """
    body = models.TextField(max_length=200)
    pub_date = models.DateTimeField(auto_now_add=True, auto_now=False)


def post_save_actions(sender, instance, created, **kwargs):
    if created:
        pass
        # post save actions if new instance is created,
        # do something with `instance` or another models
        # be careful about circular imports. \m/
Relieved Ratel

Django Wht Post Save Sign

class Status(models.Model):
    body = models.TextField(max_length=200)
    image = models.ImageField(blank=True, null=True, upload_to=get_upload_file_name)
    privacy = models.CharField(max_length=1,choices=PRIVACY, default='F')
    pub_date = models.DateTimeField(auto_now_add=True, auto_now=False)
    user = models.ForeignKey(User)

class Activity(models.Model):
    actor = models.ForeignKey(User)
    action = models.CharField(max_length=100)
    content_type = models.ForeignKey(ContentType)
    object_id = models.PositiveIntegerField()
    content_object = generic.GenericForeignKey('content_type', 'object_id')
    pub_date = models.DateTimeField(auto_now_add=True, auto_now=False)
Relieved Ratel

Django Wht Post Save Sign

from django.apps import AppConfig

class ActivityAppConfig(AppConfig):
    name = 'activity'

    def ready(self):
        import activity.signals
Relieved Ratel

Django Wht Post Save Sign

if ctype.name == 'status':
Relieved Ratel

Ответы похожие на “Django Wht Post Save Sign”

Вопросы похожие на “Django Wht Post Save Sign”

Больше похожих ответов на “Django Wht Post Save Sign” по Python

Смотреть популярные ответы по языку

Смотреть другие языки программирования