Skip to content

Instantly share code, notes, and snippets.

@godfather68
Last active July 9, 2021 21:00
Show Gist options
  • Save godfather68/dbfcfe09bb1b326e137a003ca3445a9c to your computer and use it in GitHub Desktop.
Save godfather68/dbfcfe09bb1b326e137a003ca3445a9c to your computer and use it in GitHub Desktop.
models.py for rental service API.
class House(models.Model):
"""House object"""
STATUS_CHOICES = (
('review', 'Review'),
('published', 'Published')
)
title = models.CharField(max_length=255)
price = models.DecimalField(max_digits=5, decimal_places=2)
description = models.TextField(blank=True)
publish = models.DateTimeField(default=timezone.now)
status = models.CharField(max_length=10, choices=STATUS_CHOICES, default='review')
location = models.ForeignKey('District', on_delete=models.CASCADE)
options = models.ForeignKey('Options', on_delete=models.CASCADE)
furnished = models.BooleanField(default=False)
published = PublishedManager() # Custom manager for filtering
link = models.CharField(max_length=255, blank=True)
user = models.ForeignKey(settings.AUTH_USER_MODEL, on_delete=models.CASCADE)
class Meta:
ordering = ('-publish',)
def __str__(self):
return self.title
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment