Created
August 8, 2020 17:27
-
-
Save alisonamerico/f821cfadfec85ce4dbaacceac2b68693 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 Picture(models.Model): | |
picture = models.ImageField(upload_to='pic_folder/') | |
tourist_spot = models.ForeignKey('TouristSpot', on_delete=models.CASCADE) | |
owner = models.ForeignKey(get_user_model(), on_delete=models.CASCADE) | |
class Meta: | |
verbose_name = 'Picture' | |
verbose_name_plural = 'Pictures' | |
def __str__(self): | |
"""A string representation of the model.""" | |
return f'{self.picture_url}, {self.tourist_spot}, {self.owner}' | |
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) | |
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.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