Created
March 5, 2018 19:40
-
-
Save colonelrascals/f8385009c6a233948a81f050c0a8094d to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Bookmark(models.Model): | |
user = models.ForeignKey(User, on_delete=models.CASCADE) | |
resource = models.ForeignKey("Resource", on_delete=models.CASCADE, related_name="bookmarks") | |
# meta | |
created_at = models.DateTimeField(auto_now_add=True) | |
modified_at = models.DateTimeField(auto_now=True) | |
class Meta: | |
unique_together = ('user', 'resource',) | |
ordering = ('resource',) | |
def __str__(self): | |
return "{} | {}".format(self.user, self.resource) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class BookmarkGroup(models.Model): | |
name = models.CharField(max_length=50) | |
slug = models.SlugField(null=False, unique=True) | |
bookmarks = models.ManyToManyField(Bookmark, related_name='bookmark_groups') | |
def __str__(self): | |
return self.name |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Resource(models.Model): | |
"""Initial representation of a resource.""" | |
# ID from fixture resources, for internal dedupe | |
internal_id = models.CharField(max_length=20, null=True, blank=True) | |
name = models.CharField(max_length=200) | |
description = models.TextField(null=True, blank=True) | |
categories = models.ManyToManyField("Category") | |
neighborhoods = models.ManyToManyField("Neighborhood") | |
email_contact = models.EmailField(null=True, blank=True) | |
pdf = models.ManyToManyField("PDF") | |
phone = models.CharField(max_length=200, blank=True, null=True) | |
website = models.URLField(max_length=200, blank=True, null=True) | |
# address | |
street_address = models.CharField(max_length=400, null=True, blank=True) | |
city = models.CharField(max_length=100, null=True, blank=True) | |
state = models.CharField(max_length=10, null=True, blank=True) | |
latitude = models.FloatField(null=True, blank=True) | |
longitude = models.FloatField(null=True, blank=True) | |
zip_code = models.CharField(max_length=10, null=True, blank=True) | |
# meta | |
created_at = models.DateTimeField(auto_now_add=True) | |
modified_at = models.DateTimeField(auto_now=True) | |
def __str__(self): | |
return self.name | |
def __unicode__(self): | |
return u'{}'.format(self.name) | |
@property | |
def categories_str(self): | |
return [str(t) for t in self.categories.all()] | |
@property | |
def neighborhoods_str(self): | |
return [str(t) for t in self.neighborhoods.all() if t] or ["Houston"] | |
@property | |
def bookmark(self): | |
"""This is here to make it easier to serialize a standard resource.""" | |
return getattr(self, "_bookmark", None) | |
@bookmark.setter | |
def bookmark(self, bookmark): | |
self._bookmark = bookmark |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment