|
| 1 | +import uuid |
| 2 | +from taggit.managers import TaggableManager |
| 3 | +from django.conf import settings |
1 | 4 | from django.db import models
|
| 5 | +from django.utils import timezone |
| 6 | +from django.contrib.auth import get_user_model |
| 7 | +from tagging.managers import CustomTaggableManager |
| 8 | +from tagging.models import CustomTag, TaggedItems |
2 | 9 |
|
3 |
| -# Create your models here. |
| 10 | +def get_sentinel_user(): |
| 11 | + return get_user_model().objects.get_or_create(username='deleted')[0] |
| 12 | + |
| 13 | + |
| 14 | +def get_tags_display(self): |
| 15 | + return self.tags.values_list('name', flat=True) |
| 16 | + |
| 17 | + |
| 18 | +class OSProjects(models.Model): |
| 19 | + |
| 20 | + guid = models.UUIDField(default=uuid.uuid1, editable=False) |
| 21 | + |
| 22 | + title = models.CharField(max_length=200) |
| 23 | + |
| 24 | + project_creator = models.CharField(blank=True, max_length=200) |
| 25 | + |
| 26 | + description = models.TextField(blank=True, max_length=600) |
| 27 | + |
| 28 | + # specific URL of project home or github repo |
| 29 | + url = models.URLField(max_length=300) |
| 30 | + |
| 31 | + # user who posted the project |
| 32 | + user = models.ForeignKey(settings.AUTH_USER_MODEL, on_delete=models.SET(get_sentinel_user)) |
| 33 | + |
| 34 | + # creation date of project entry |
| 35 | + created = models.DateTimeField(auto_now_add=True) |
| 36 | + |
| 37 | + # modification date of project entry |
| 38 | + modified = models.DateTimeField(default=timezone.now) |
| 39 | + |
| 40 | + # TO DO: DEFINE FINAL DATA TYPE OF THIS FIELD |
| 41 | + open_to_contributors = models.BooleanField() |
| 42 | + |
| 43 | + # TO DO: DEFINE RELATIONS FOR THIS FIELD |
| 44 | + # contributing_cb_members = ????? |
| 45 | + |
| 46 | + # Allow tags to be used across entities |
| 47 | + # E.g. so we can create composite views showing all entities sharing a common tag |
| 48 | + tags = TaggableManager(through=TaggedItems, manager=CustomTaggableManager, blank=True) |
| 49 | + |
| 50 | + def __str__(self): |
| 51 | + """A string representation of the model.""" |
| 52 | + return self.title |
0 commit comments