class Association(core.models.Model):
    pinned = models.BooleanField(
        'Im Intro der Gruppe anheften',
        default=False,
        help_text=
        'Angeheftete Beiträge werden auf der Gruppenseite zuerst angezeigt. Sie '
        'können beispielsweise für allgemeine Einleitungs- und Beschreibungstexte '
        'verwendet werden.')
    public = models.BooleanField(
        'Öffentlich',
        default=False,
        help_text=
        'Öffentliche Beiträge sind auch für Besucherinnen sichtbar, die nicht '
        'Mitglied der Gruppe sind. Benachrichtigungen werden an Mitglieder und '
        'Abonnentinnen versendet.')
    slug = models.SlugField(
        'Kurzname',
        default=None,
        null=True,
        help_text=
        'Der Kurzname wird beispielsweise in der Webadresse des Beitrags '
        'verwendet.')

    deleted = models.DateTimeField(null=True, blank=True)

    container = contenttypes.GenericForeignKey('container_type',
                                               'container_id')
    container_id = models.PositiveIntegerField()
    container_type = models.ForeignKey('contenttypes.ContentType',
                                       related_name='container_associations',
                                       on_delete=models.CASCADE)

    entity = contenttypes.GenericForeignKey('entity_type', 'entity_id')
    entity_id = models.PositiveIntegerField()
    entity_type = models.ForeignKey('contenttypes.ContentType',
                                    related_name='entity_associations',
                                    on_delete=models.CASCADE)

    objects = models.Manager.from_queryset(querysets.Association)()

    class Meta:
        unique_together = ('entity_id', 'entity_type', 'slug')

    def __str__(self):
        return str(self.container)

    def get_absolute_url(self):
        return self.container.get_url_for(self)
class LogObjectRelation(models.Model):
    content_type = models.ForeignKey(
        ContentType,
        verbose_name=_(u"Content type"),
        related_name="log_object",
        blank=True,
        null=True,
        on_delete=None,
    )
    content_id = models.PositiveIntegerField(_(u"Content id"),
                                             blank=True,
                                             null=True)
    content = fields.GenericForeignKey(ct_field="content_type",
                                       fk_field="content_id")
    create_time = models.DateTimeField(blank=True,
                                       auto_now_add=True,
                                       help_text=_('log create time'),
                                       verbose_name=_('create time'))
    source_state = models.CharField(_("source state"),
                                    max_length=36,
                                    null=True,
                                    blank=True)
    transition = models.CharField(_("transition"),
                                  max_length=36,
                                  null=True,
                                  blank=True)
    state = models.CharField(_("current state"), max_length=36)

    def __unicode__(self):
        return "%s %s - %s" % (self.content_type.name, self.content_id,
                               self.state)

    def __str__(self):
        return self.__unicode__()
Exemple #3
0
class Rating(models.Model):
    RATINGS = [(x, x) for x in range(1, 6)]

    rating = models.PositiveIntegerField(choices=RATINGS, default=3)
    content_type = models.ForeignKey(ContentType)
    object_id = models.PositiveIntegerField()
    content_object = fields.GenericForeignKey('content_type', 'object_id')
Exemple #4
0
class I18n(models.Model):
    """Internalizations"""
    lang = models.CharField(max_length=8,
                            help_text=_("Language code"),
                            choices=settings.LANG_CHOICE,
                            verbose_name=_("Language"))
    content_type = models.ForeignKey(
        ContentType,
        blank=True,
        null=True,
        verbose_name=_("Entity_type"),
        on_delete=models.CASCADE,
        help_text=_("Type of entity - i18n value owner."))
    column_name = models.CharField(max_length=30,
                                   verbose_name=_("Column name"),
                                   choices=COLS,
                                   help_text=_("Virtual column name."))
    object_id = models.PositiveIntegerField(
        _("Object ID"), help_text=_("Reference to entity object."))
    text = models.TextField(
        _("Text"), help_text=_("Content of column in exact language."))
    entity = fields.GenericForeignKey("content_type", "object_id")

    class Meta:
        unique_together = (('content_type', 'object_id', 'column_name',
                            'lang'), )
        db_table = 'com_i18n'
Exemple #5
0
class ModelChange(models.Model):
    # This is used by auditing.middleware.GlobalRequestMiddleware to store
    # the current request object, if any, per thread.
    thread = threading.local()

    PRIMARY_MODELS = [Bank, User, Package, Investment, Transactions]

    # Create/update/delete
    created_at = models.DateTimeField(auto_now_add=True)
    updated_at = models.DateTimeField(auto_now=True)
    kind = models.CharField(max_length=6, choices=KIND_CHOICES)
    user = models.ForeignKey(User,
                             blank=True,
                             null=True,
                             on_delete=models.SET_NULL)
    # What fields were changed to what values (if create or update)
    changes = models.CharField(null=True, blank=True, max_length=200)
    subject = models.CharField(null=True, blank=True, max_length=200)
    # The object whose changes we will want to query later (Building, Location)
    primary = fields.GenericForeignKey("primary_ct", "primary_id")

    primary_ct = models.ForeignKey(ContentType,
                                   related_name="primaries",
                                   on_delete=models.CASCADE)
    primary_id = models.PositiveIntegerField()
    colour_code = models.CharField(max_length=12, choices=COLOUR_CHOICES)
Exemple #6
0
class Like(DatetimeModel):
    """ Annotation "J'aime" sur un objet arbitraire. """

    # Champs
    author = models.ForeignKey(settings.AUTH_USER_MODEL, null=False, related_name='likees', verbose_name=_("Author"))
    content_type = models.ForeignKey('contenttypes.ContentType', null=True, blank=False, verbose_name=_("Content type"),
                                     limit_choices_to={'app_label__in': ['content']})
    object_id = models.PositiveIntegerField(null=True, blank=False, verbose_name=_("Object Id"))
    content_object = fields.GenericForeignKey('content_type', 'object_id')
    objects = LikeManager()

    # Overrides
    def delete(self, *args, **kwargs):
        """ Supprimer l'objet de la base de données """
        self.content_type = None
        self.object_id = None
        super().delete(*args, **kwargs)

    def __str__(self):
        """ Renvoyer la représentation unicode de l'objet """
        return _("{user} likes {target}").format(user=self.author.username, target=self)

    # Métadonnées
    class Meta:
        verbose_name = _("like")
        verbose_name_plural = _("likes")
        unique_together = (('author', 'content_type', 'object_id'),)
        permissions = [['like_content', "Can like content"]]
        app_label = 'social'
Exemple #7
0
class URL_i18n(models.Model):
    '''
    URL of a particular type in a particular language
    '''

    URLTYPES = (
        ('info', 'Info'),
        ('policy', 'Policy'),
    )
    url = models.CharField(max_length=180, db_column='URL')
    lang = models.CharField(
        max_length=5, choices=get_choices_from_settings('URL_NAME_LANGS'))
    urltype = models.CharField(max_length=10,
                               choices=URLTYPES,
                               db_column='type')
    content_type = models.ForeignKey(ContentType, blank=True, null=True)
    object_id = models.PositiveIntegerField(blank=True, null=True)
    content_object = fields.GenericForeignKey('content_type', 'object_id')

    class Meta:
        verbose_name = "Url (i18n)"
        verbose_name_plural = "Urls (i18n)"

    def __unicode__(self):
        return self.url
class Comment(models.Model):
    """
    Comment
    """
    content_type = models.ForeignKey(ContentType, on_delete=models.CASCADE)
    object_id = models.PositiveIntegerField()
    parent = fields.GenericForeignKey('content_type', 'object_id')

    contents = models.CharField(max_length=32, verbose_name='내용')
    writer = models.ForeignKey(Fbuser,
                               on_delete=models.CASCADE,
                               verbose_name='작성자')
    registered_dttm = models.DateTimeField(auto_now_add=True,
                                           verbose_name='등록시간')

    def __repr__(self):
        return 'Comment()'

    def __str__(self):
        return self.contents[:10]

    class Meta:
        db_table = 'programmers_comment'
        verbose_name = '댓글'
        verbose_name_plural = '댓글'
Exemple #9
0
class Notification(models.Model):
    source = models.ForeignKey(ContentType, on_delete=models.CASCADE)
    object_id = models.PositiveIntegerField()
    content_object = fields.GenericForeignKey('source', 'object_id')
    destination = models.ForeignKey(settings.AUTH_USER_MODEL,
                                    on_delete=models.CASCADE,
                                    related_name="notifications")
    title = models.CharField(max_length=255)
    food = models.ForeignKey(FoodMenu,
                             on_delete=models.CASCADE,
                             related_name="notifications",
                             null=True,
                             blank=True)
    order = models.ForeignKey(Order,
                              on_delete=models.CASCADE,
                              related_name="notifications",
                              null=True,
                              blank=True)
    cart = models.ForeignKey(FoodCart,
                             on_delete=models.CASCADE,
                             related_name="notifications",
                             null=True,
                             blank=True)
    date_created = models.DateTimeField(auto_now=True)
    is_seen = models.BooleanField(default=False)
    description = models.TextField(null=True, blank=True)
Exemple #10
0
class Follow(models.Model):
    """
    Generic Follow class. A Follow object is a generic reference between a
    user and another Django model.
    """

    user = models.ForeignKey('members.Member')
    content_type = models.ForeignKey(ContentType)
    object_id = models.PositiveIntegerField()
    followed_object = fields.GenericForeignKey('content_type', 'object_id')

    def __str__(self):
        if self.followed_object:
            return str(self.followed_object)
        return self.id

    def validate_unique(self, exclude=None):
        qs = Follow.objects.filter(
            user=self.user, content_type=self.content_type,
            object_id=self.object_id)
        if qs.count() > 0:
            return False
        return True

    def save(self, *args, **kwargs):
        if self.validate_unique():
            super(Follow, self).save(*args, **kwargs)
Exemple #11
0
class Like(models.Model):
    """
    Like
    """
    content_type = models.ForeignKey(
        ContentType, on_delete=models.CASCADE)
    object_id = models.PositiveIntegerField()
    parent = fields.GenericForeignKey('content_type', 'object_id')

    writer = models.ForeignKey(Fbuser,
                               on_delete=models.CASCADE,
                               verbose_name='작성자')
    registered_dttm = models.DateTimeField(auto_now_add=True,
                                           verbose_name='등록시간')

    def __repr__(self):
        return 'Like()'

    def __str__(self):
        return '({}) => {} [{}]'.format(self.writer, self.content_type, self.object_id)

    class Meta:
        db_table = 'programmers_like'
        verbose_name = '좋아요'
        verbose_name_plural = '좋아요'
Exemple #12
0
class EventRelation(with_metaclass(ModelBase, *get_model_bases())):
    '''
    This is for relating data to an Event, there is also a distinction, so that
    data can be related in different ways.  A good example would be, if you have
    events that are only visible by certain users, you could create a relation
    between events and users, with the distinction of 'visibility', or
    'ownership'.

    event: a foreign key relation to an Event model.
    content_type: a foreign key relation to ContentType of the generic object
    object_id: the id of the generic object
    content_object: the generic foreign key to the generic object
    distinction: a string representing a distinction of the relation, User could
    have a 'viewer' relation and an 'owner' relation for example.

    DISCLAIMER: while this model is a nice out of the box feature to have, it
    may not scale well.  If you use this keep that in mind.
    '''
    event = models.ForeignKey(Event, on_delete=models.CASCADE, verbose_name=_("event"))
    content_type = models.ForeignKey(ContentType, on_delete=models.CASCADE)
    object_id = models.IntegerField()
    content_object = fields.GenericForeignKey('content_type', 'object_id')
    distinction = models.CharField(_("distinction"), max_length=20, null=True)

    objects = EventRelationManager()

    class Meta(object):
        verbose_name = _("event relation")
        verbose_name_plural = _("event relations")
        app_label = 'schedule'

    def __str__(self):
        return '%s(%s)-%s' % (self.event.title, self.distinction, self.content_object)
Exemple #13
0
class GenericTransitionLog(BaseTransitionLog):
    """Abstract model for a minimal database logging setup.

    Specializes BaseTransitionLog to use a GenericForeignKey.

    Attributes:
        modified_object (django.db.model.Model): the object affected by this
            transition.
        from_state (str): the name of the origin state
        to_state (str): the name of the destination state
        transition (str): The name of the transition being performed.
        timestamp (datetime): The time at which the Transition was performed.
    """
    MODIFIED_OBJECT_FIELD = 'modified_object'

    content_type = models.ForeignKey(
        ct_models.ContentType,
        verbose_name=_("Content type"),
        blank=True,
        null=True,
        on_delete=models.CASCADE,
    )
    content_id = models.PositiveIntegerField(_("Content id"),
                                             blank=True,
                                             null=True,
                                             db_index=True)
    modified_object = ct_fields.GenericForeignKey(ct_field="content_type",
                                                  fk_field="content_id")

    class Meta:
        ordering = ('-timestamp', 'transition')
        verbose_name = _('XWorkflow transition log')
        verbose_name_plural = _('XWorkflow transition logs')
        abstract = True
Exemple #14
0
class AuditLogEntry(models.BaseModel):
    """Auditlog model"""

    ACTION_ADDED = 10
    ACTION_CHANGED = 20
    ACTION_DELETED = 30

    action_choices = [
        (ACTION_ADDED, _('Added')),
        (ACTION_CHANGED, _('Changed')),
        (ACTION_DELETED, _('Deleted')),
    ]

    content_type = models.ForeignKey('contenttypes.ContentType',
                                     models.CASCADE,
                                     related_name='+')
    object_id = models.BigIntegerField(blank=True, null=True)
    content_object = fields.GenericForeignKey('content_type', 'object_id')
    object_verbose_name = models.TextField(default='', blank=True)

    user = models.ForeignKey(settings.AUTH_USER_MODEL,
                             models.SET_NULL,
                             blank=True,
                             null=True,
                             related_name='+')
    action = models.IntegerField(choices=action_choices)
    changes = models.JSONField()

    class Meta:
        """Model meta description"""

        indexes = [
            models.Index(fields=['content_type', 'object_id']),
        ]
Exemple #15
0
class LinkedPromotion(models.Model):

    # We use generic foreign key to link to a promotion model
    content_type = models.ForeignKey(ContentType, on_delete=models.CASCADE)
    object_id = models.PositiveIntegerField()
    content_object = fields.GenericForeignKey('content_type', 'object_id')

    position = models.CharField(_("Position"),
                                max_length=100,
                                help_text="Position on page")
    display_order = models.PositiveIntegerField(_("Display Order"), default=0)
    clicks = models.PositiveIntegerField(_("Clicks"), default=0)
    date_created = models.DateTimeField(_("Date Created"), auto_now_add=True)

    class Meta:
        abstract = True
        app_label = 'promotions'
        ordering = ['-clicks']
        verbose_name = _("Linked Promotion")
        verbose_name_plural = _("Linked Promotions")

    def record_click(self):
        self.clicks += 1
        self.save()

    record_click.alters_data = True
Exemple #16
0
class Documentos(models.Model):
    ''' Modelo generico para subir los documentos en distintos app'''
    content_type = models.ForeignKey(ContentType, on_delete=models.DO_NOTHING)
    object_id = models.IntegerField(db_index=True)
    content_object = fields.GenericForeignKey('content_type', 'object_id')

    nombre_doc = models.CharField("Nombre",
                                  max_length=200,
                                  null=True,
                                  blank=True)
    adjunto = models.FileField("Adjunto",
                               upload_to=get_file_path,
                               null=True,
                               blank=True)
    tags_doc = TaggableManager("Tags",
                               help_text='Separar elementos con "," ',
                               blank=True)

    fileDir = 'documentos/'

    class Meta:
        verbose_name_plural = "Documentos"

    def __str__(self):
        return self.nombre_doc
Exemple #17
0
class Attachment(models.Model):
    objects = managers.AttachmentManager()

    content_type = models.ForeignKey(ContentType)
    object_id = models.PositiveIntegerField()
    content_object = fields.GenericForeignKey('content_type', 'object_id')
    title = models.CharField(max_length=128)
    attachment = models.FileField(upload_to="attachment")
    publicly_available = models.BooleanField(default=True)
    description = models.TextField(blank=True)

    def __str__(self):
        return self.title

    def get_absolute_url(self):
        return self.content_object.get_absolute_url()

    def get_edit_url(self):
        return reverse('assessment:attachment_update', args=[self.pk])

    def get_delete_url(self):
        return reverse('assessment:attachment_delete', args=[self.pk])

    def get_dict(self):
        return {
            "url": self.get_absolute_url(),
            "url_delete": self.get_delete_url(),
            "url_update": self.get_update_url(),
            "title": self.title,
            "description": self.description
        }

    def get_assessment(self):
        return self.content_object.get_assessment()
Exemple #18
0
class Attachment(Base):

    description = models.TextField()

    class Meta:
        app_label = "core"
        db_table = 'attachment'
        ordering = ['-date_created']

    content_type = models.ForeignKey(ContentType)
    object_id = models.PositiveIntegerField()
    content_object = fields.GenericForeignKey('content_type', 'object_id')

    def __str__(self):
        return self.filename()

    def filename(self):
        return os.path.basename(self.file.name)

    def get_upload_path(instance, filename):
        return os.path.join("{0}/{1}_{2}/{3}".format(
            constants.ATTACHMENT_FOLDER, instance.content_type.name,
            instance.object_id, filename))

    file = models.FileField(upload_to=get_upload_path,
                            storage=UniqueFileSystemStorage())
Exemple #19
0
class Award(models.Model):
    """The awarding of a Badge to a User."""
    user = models.ForeignKey(User,
                             related_name='award_user',
                             on_delete=models.CASCADE)
    badge = models.ForeignKey(BadgeData,
                              related_name='award_badge',
                              on_delete=models.CASCADE)
    content_type = models.ForeignKey(ContentType, on_delete=models.CASCADE)
    object_id = models.PositiveIntegerField()
    content_object = fields.GenericForeignKey('content_type', 'object_id')
    awarded_at = models.DateTimeField(default=timezone.now)
    notified = models.BooleanField(default=False)

    def __str__(self):
        return '[%s] is awarded a badge [%s] at %s' % (
            self.user.username, self.badge.get_name(), self.awarded_at)

    def __lt__(self, other):
        return self.id < other.id

    class Meta:
        app_label = 'askbot'
        db_table = 'award'
        verbose_name = _("award")
        verbose_name_plural = _("awards")
Exemple #20
0
class Module(models.Model):
    content_type = models.ForeignKey(ContentType)
    object_id = models.PositiveIntegerField()
    content_object = fields.GenericForeignKey('content_type', 'object_id')

    def __str__(self):
        return self.content_object.name
Exemple #21
0
class CustomFieldValue(models.Model):
    """
    A field instance -- contains the actual data.  There are many of these, for
    each value that corresponds to a CustomField for a given model.
    """
    field = models.ForeignKey(CustomField,
                              related_name='instance',
                              on_delete=models.CASCADE)
    value = models.CharField(max_length=5000, blank=True, null=True)
    object_id = models.PositiveIntegerField()
    content_type = models.ForeignKey(ContentType,
                                     blank=True,
                                     null=True,
                                     on_delete=models.CASCADE)
    content_object = fields.GenericForeignKey('content_type', 'object_id')

    def __str__(self):
        return text_type(self.value)

    def save(self, *args, **kwargs):
        super(CustomFieldValue, self).save(*args, **kwargs)
        if not self.content_type:
            self.content_type = self.field.content_type
            self.save()

    def clean(self):
        form_field = self.get_form_field()
        form_field.clean(self.value)
        return super(CustomFieldValue, self).clean()

    def get_form_field(self):
        return self.field.get_form_field()

    class Meta:
        unique_together = ('field', 'object_id')
Exemple #22
0
class ObservedItem(models.Model):

    user = models.ForeignKey(User,
                             verbose_name=_("user"),
                             on_delete=models.CASCADE)

    content_type = models.ForeignKey(ContentType, on_delete=models.CASCADE)
    object_id = models.PositiveIntegerField()
    observed_object = fields.GenericForeignKey("content_type", "object_id")

    notice_type = models.ForeignKey(NoticeType,
                                    verbose_name=_("notice type"),
                                    on_delete=models.CASCADE)

    added = models.DateTimeField(_("added"), default=datetime.datetime.now)

    # the signal that will be listened to send the notice
    signal = models.TextField(verbose_name=_("signal"))

    objects = ObservedItemManager()

    class Meta:
        ordering = ["-added"]
        verbose_name = _("observed item")
        verbose_name_plural = _("observed items")
        app_label = "notification"

    def send_notice(self, extra_context=None):
        if extra_context is None:
            extra_context = {}
        extra_context.update({"observed": self.observed_object})
        send([self.user], self.notice_type.label, extra_context)
Exemple #23
0
class TaggedTag(models.Model):
    # TaggedTag.object.get(tag)
    tag = models.ForeignKey(Tags)  # FK to the tag table
    content_type = models.ForeignKey(ContentType)
    object_id = models.PositiveIntegerField()
    tagged_item = fields.GenericForeignKey(
        'content_type', 'object_id')  # FK to the user or event table
Exemple #24
0
class StripeCharge(StripeBasicModel):
    user = models.ForeignKey(USER_MODEL, on_delete=models.CASCADE, related_name='stripe_charges')
    customer = models.ForeignKey(StripeCustomer, on_delete=models.SET_NULL, null=True)
    amount = models.IntegerField(null=True, help_text=_("in cents"))
    is_charged = models.BooleanField(default=False)
    is_refunded = models.BooleanField(default=False)
    charge_attempt_failed = models.BooleanField(default=False)
    stripe_charge_id = models.CharField(max_length=255, blank=True, db_index=True)
    stripe_refund_id = models.CharField(max_length=255, blank=True, db_index=True)
    description = models.CharField(max_length=255, help_text=_("Description sent to Stripe"))
    comment = models.CharField(max_length=255, help_text=_("Comment for internal information"))
    content_type = models.ForeignKey(ContentType, null=True, on_delete=models.CASCADE)
    object_id = models.PositiveIntegerField(null=True, db_index=True)
    source = generic.GenericForeignKey('content_type', 'object_id')

    def charge(self):
        if self.is_charged:
            raise StripeMethodNotAllowed("Already charged.")

        stripe.api_key = stripe_settings.API_KEY
        customer = StripeCustomer.get_latest_active_customer_for_user(self.user)
        self.customer = customer
        if customer:
            try:
                stripe_charge = stripe.Charge.create(
                    amount=self.amount,
                    currency="usd",
                    customer=customer.stripe_customer_id,
                    description=self.description
                )
            except stripe.error.CardError as e:
                self.charge_attempt_failed = True
                self.is_charged = False
                self.save()
                stripe_charge_card_exception.send(sender=StripeCharge, instance=self, exception=e)
                return  # just exit.
            except stripe.error.StripeError:
                self.is_charged = False
                self.save()
                raise

            self.stripe_charge_id = stripe_charge["id"]
            self.stripe_response = stripe_charge
            self.is_charged = True
            self.save()
            stripe_charge_succeeded.send(sender=StripeCharge, instance=self)
            return stripe_charge

    def refund(self):
        if not self.is_charged:
            raise StripeMethodNotAllowed("Cannot refund not charged transaction.")

        if self.is_refunded:
            raise StripeMethodNotAllowed("Already refunded.")

        stripe_refund = stripe.Refund.create(charge=self.stripe_charge_id)
        self.is_refunded = True
        self.stripe_refund_id = stripe_refund["id"]
        self.save()
Exemple #25
0
class Feed(models.Model):
    event = models.ForeignKey(on_delete=models.CASCADE, to=Event)
    content_type = models.ForeignKey(on_delete=models.CASCADE,
                                     to=ct_models.ContentType,
                                     db_index=True)
    object_id = models.PositiveIntegerField(db_index=True)
    scope = ct_fields.GenericForeignKey('content_type', 'object_id')
    objects = FeedManager()
Exemple #26
0
class LinkedContent(models.Model):
    content_type = models.ForeignKey(ContentType)
    object_id = models.PositiveIntegerField(db_index=True)
    content_object = fields.GenericForeignKey('content_type', 'object_id')

    def __unicode__(self):
        return u"<# LinkedContent - pk: %s, type: %s>" % (self.object_id,
                                                          self.content_type)
Exemple #27
0
class Quota(UuidMixin, AlertThresholdMixin, LoggableMixin, ReversionMixin,
            models.Model):
    """
    Abstract quota for any resource.

    Quota can exist without scope: for example, a quota for all projects or all
    customers on site.
    If quota limit is set to -1 quota will never be exceeded.
    """
    class Meta:
        unique_together = (('name', 'content_type', 'object_id'), )

    limit = models.FloatField(default=-1)
    usage = models.FloatField(default=0)
    name = models.CharField(max_length=150, db_index=True)

    content_type = models.ForeignKey(ct_models.ContentType, null=True)
    object_id = models.PositiveIntegerField(null=True)
    scope = ct_fields.GenericForeignKey('content_type', 'object_id')

    objects = managers.QuotaManager('scope')
    tracker = FieldTracker()

    def __str__(self):
        return '%s quota for %s' % (self.name, self.scope)

    def is_exceeded(self, delta=None, threshold=None):
        """
        Check is quota exceeded

        If delta is not None then checks if quota exceeds with additional delta usage
        If threshold is not None then checks if quota usage over threshold * limit
        """
        if self.limit == -1:
            return False

        usage = self.usage
        limit = self.limit

        if delta is not None:
            usage += delta
        if threshold is not None:
            limit = threshold * limit

        return usage > limit

    def get_log_fields(self):
        return ('uuid', 'name', 'limit', 'usage', 'scope')

    def get_field(self):
        fields = self.scope.get_quotas_fields()
        try:
            return next(f for f in fields if f.name == self.name)
        except StopIteration:
            return

    def is_over_threshold(self):
        return self.usage >= self.threshold