Exemple #1
0
class SiteRelated(models.Model):
    """
    Abstract model for all things site-related. Adds a foreignkey to
    Django's ``Site`` model, and filters by site with all querysets.
    See ``mezzanine.utils.sites.current_site_id`` for implementation
    details.
    """

    objects = CurrentSiteManager()

    class Meta:
        abstract = True

    site = models.ForeignKey("sites.Site", editable=False,
                              related_name="%(class)ss")

    def save(self, update_site=False, *args, **kwargs):
        """
        Set the site to the current site when the record is first
        created, or the ``update_site`` argument is explicitly set
        to ``True``.
        """
        if update_site or (self.id is None and self.site_id is None):
            self.site_id = current_site_id()
        super(SiteRelated, self).save(*args, **kwargs)
Exemple #2
0
class TODOItem(models.Model):
    """Tracks translation/content updates needed across sites."""

    ACTION_CREATE = 1
    ACTION_EDIT = 2
    ACTION_DELETE = 3

    ACTION_CHOICES = (
        (ACTION_CREATE, _('Create')),
        (ACTION_EDIT, _('Edit')),
        (ACTION_DELETE, _('Delete')),
    )

    title = title = models.CharField(_('Title'), max_length=500)
    slug =  models.CharField(_('URL'), max_length=2000, blank=True, null=True)
    page = models.ForeignKey('pages.Page', null=True)
    action = models.IntegerField(_('Action'), choices=ACTION_CHOICES)
    description = models.TextField(_('Description'), blank=True)
    editor = models.ForeignKey(settings.AUTH_USER_MODEL, verbose_name=_('Editor'),
        related_name='translation_edits')
    site = models.ForeignKey('sites.Site', editable=False)
    created = models.DateTimeField(null=True, editable=False, default=timezone.now)
    resolved = models.DateTimeField(null=True, editable=False)
    resolved_by = models.ForeignKey(settings.AUTH_USER_MODEL, null=True, editable=False)

    objects = models.Manager()
    site_objects = CurrentSiteManager()