Last active
August 6, 2020 18:03
-
-
Save alisonamerico/96edea36a25bb73c10eaa51c07c9aed9 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
# api/models.py | |
class Picture(models.Model): | |
picture_url = models.ImageField(upload_to='pic_folder/', default='pic_folder/none/no-img.jpg') | |
tourist_spot = models.ForeignKey('TouristSpot', on_delete=models.CASCADE) | |
class TouristSpot(models.Model): | |
""" | |
This class contains the representation of the fields in the TouristSpot table. | |
""" | |
CATEGORY_CHOICES = [ | |
('PARK', 'Park'), | |
('MUSEUM', 'Museum'), | |
('THEATER', 'Theater'), | |
('MONUMENT', 'Monument'), | |
] | |
pictures = models.ForeignKey('api.Picture', blank=True, null=True, on_delete=models.CASCADE) | |
name = models.CharField(max_length=100) | |
geographical_location = models.PointField(geography=True, default=Point(0.0, 0.0)) | |
category = models.CharField(max_length=50, choices=CATEGORY_CHOICES) | |
owner = models.ForeignKey(get_user_model(), on_delete=models.CASCADE) | |
created = models.DateTimeField('Created in', auto_now_add=True) | |
modified = models.DateTimeField('Modified in', auto_now=True) | |
class Meta: | |
verbose_name = 'TouristSpot' | |
verbose_name_plural = 'TouristSpots' | |
ordering = ['-created'] | |
def __str__(self): | |
"""A string representation of the model.""" | |
return f'{self.owner.first_name}, {self.name}' | |
class Favorite(models.Model): | |
""" | |
This class contains the relationship between tourist spots and the tourist. | |
Where a tourist spot may be a favorite of one or more tourists and a tourist | |
may favor one or more tourist spots. | |
""" | |
tourist = models.ForeignKey(get_user_model(), on_delete=models.CASCADE) | |
tourist_spot = models.ForeignKey('TouristSpot', on_delete=models.CASCADE) | |
class Meta: | |
verbose_name = 'Favorite' | |
verbose_name_plural = 'Favorites' | |
ordering = ['-tourist_spot'] | |
def __str__(self): | |
"""A string representation of the model.""" | |
return f'{self.tourist_spot}, {self.tourist}' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment