40 lines
1.1 KiB
Python
40 lines
1.1 KiB
Python
from django.db import models
|
|
from django.core.validators import MaxValueValidator, MinLengthValidator
|
|
|
|
|
|
class Address(models.Model):
|
|
"""
|
|
Model of details for a physical location of a property
|
|
"""
|
|
|
|
class Meta:
|
|
"""
|
|
Fix the plural displayed in admin
|
|
"""
|
|
verbose_name_plural = "Addresses"
|
|
|
|
|
|
number = models.PositiveIntegerField(validators=[MaxValueValidator(9999)])
|
|
street = models.CharField(max_length=64)
|
|
city = models.CharField(max_length=64)
|
|
state = models.CharField(max_length=2, validators=[MinLengthValidator(2)])
|
|
zip_code = models.PositiveIntegerField(validators=[MaxValueValidator(99999)])
|
|
country_iso_code = models.CharField(max_length=3, validators=[MinLengthValidator(3)])
|
|
|
|
def __str__(self):
|
|
""" Display object with basic address """
|
|
return f'{self.number} {self.street}'
|
|
|
|
|
|
|
|
class Letting(models.Model):
|
|
"""
|
|
Model of an announce for a property to rent
|
|
"""
|
|
title = models.CharField(max_length=256)
|
|
address = models.OneToOneField(Address, on_delete=models.CASCADE)
|
|
|
|
def __str__(self):
|
|
""" display object with title """
|
|
return self.title
|