Test coverage report: user_media.models

# user_media.models: 16 total statements, 100.0% covered

Generated: Thu 2013-03-14 13:13 SGT

Source file: /Users/martin/Repos/django-user-media/user_media/models.py

Stats: 10 executed, 0 missed, 6 excluded, 40 ignored

1. `"""Models for the ``django-user-media`` app."""`
2. `import os`
3. `import uuid`
4. ``
5. `from django.contrib.contenttypes import generic`
6. `from django.contrib.contenttypes.models import ContentType`
7. `from django.db import models`
8. `from django.utils.translation import ugettext_lazy as _`
9. ``
10. ``
11. `def get_image_file_path(instance, filename):`
12. `"""Returns a unique filename for images."""`
13. `ext = filename.split('.')[-1]`
14. `filename = '%s.%s' % (uuid.uuid4(), ext)`
15. `return os.path.join(`
16. `'user_media', str(instance.user.pk), 'images', filename)`
17. ``
18. ``
19. `class UserMediaImage(models.Model):`
20. `"""`
21. `An image that can be uploaded by a user.`
22. ``
23. `If the image belongs to a certain object that is owned by the user, it`
24. `can be tied to that object using the generic foreign key. That object`
25. `must have a foreign key to ``auth.User`` and that field must be called`
26. ```user``.`
27. ``
28. `:user: The user this image belongs to.`
29. `:content_type: If this image belongs to a certain object (i.e. a Vehicle),`
30. `this should be the object's ContentType.`
31. `:object_id: If this image belongs to a certain object (i.e. a Vehicle),`
32. `this should be the object's ID.`
33. `:image: The uploaded image.`
34. ``
35. `"""`
36. `user = models.ForeignKey(`
37. `'auth.User',`
38. `verbose_name=_('User'),`
39. `)`
40. ``
41. `content_type = models.ForeignKey(`
42. `ContentType,`
43. `null=True, blank=True,`
44. `)`
45. ``
46. `object_id = models.PositiveIntegerField(`
47. `null=True, blank=True`
48. `)`
49. ``
50. `content_object = generic.GenericForeignKey('content_type', 'object_id')`
51. ``
52. `image = models.ImageField(`
53. `upload_to=get_image_file_path,`
54. `null=True, blank=True,`
55. `verbose_name=_('Image'),`
56. `)`