subscribe.models: 14 total statements, 100.0% covered

Generated: Thu 2013-02-28 14:58 SGT

Source file: /Users/martin/Repos/django-subscribe/subscribe/models.py

Stats: 8 executed, 0 missed, 6 excluded, 23 ignored

  1. """Models for the ``subscribe`` app."""
  2. from django.contrib.contenttypes import generic
  3. from django.contrib.contenttypes.models import ContentType
  4. from django.db import models
  5. from django.utils.translation import ugettext_lazy as _
  6. class Subscription(models.Model):
  7. """
  8. Allows a ``User`` to subscribe to anything.
  9. :user: The ``User`` who subscribed to something.
  10. :content_object: Generic foreign key to the thing that the user is
  11. subscribed to.
  12. :date: Date when the subscription was created.
  13. """
  14. class Meta:
  15. unique_together = ('user', 'content_type', 'object_id', )
  16. user = models.ForeignKey(
  17. 'auth.User',
  18. verbose_name=_('User'),
  19. )
  20. content_type = models.ForeignKey(ContentType)
  21. object_id = models.PositiveIntegerField()
  22. content_object = generic.GenericForeignKey('content_type', 'object_id')
  23. creation_date = models.DateTimeField(
  24. auto_now_add=True,
  25. verbose_name=_('Creation date'),
  26. )
  27. def __unicode__(self):
  28. return '{0} subscribed to {1}'.format(
  29. self.user.email, self.content_object)