add doctstings

This commit is contained in:
2025-09-08 11:58:02 +02:00
parent 2fd139de55
commit dd5bccf708
6 changed files with 45 additions and 0 deletions

View File

@@ -3,6 +3,17 @@ from django.core.validators import MaxValueValidator, MinLengthValidator
class Address(models.Model):
"""
Details of the 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)
@@ -11,12 +22,18 @@ class Address(models.Model):
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):
"""
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

View File

@@ -3,12 +3,22 @@ from lettings.models import Letting
def index(request):
"""
letting's index page. Retrieve all objects in db then give list to template
:param request; None
:return: render and display template HTML
"""
lettings_list = Letting.objects.all()
context = {'lettings_list': lettings_list}
return render(request, 'lettings/index.html', context)
def letting(request, letting_id):
"""
display detail of a particular Letting object
:param request: None
:return: render and display template HTML
"""
letting = Letting.objects.get(id=letting_id)
context = {
'title': letting.title,