add doctstings
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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,
|
||||
|
||||
Binary file not shown.
@@ -2,4 +2,9 @@ from django.shortcuts import render
|
||||
|
||||
|
||||
def index(request):
|
||||
"""
|
||||
Main index of app, home page
|
||||
:param request: None
|
||||
:return: render and display homepage
|
||||
"""
|
||||
return render(request, 'index.html')
|
||||
|
||||
@@ -3,6 +3,9 @@ from django.contrib.auth.models import User
|
||||
|
||||
|
||||
class Profile(models.Model):
|
||||
"""
|
||||
Defines a service user
|
||||
"""
|
||||
user = models.OneToOneField(User, on_delete=models.CASCADE)
|
||||
favorite_city = models.CharField(max_length=64, blank=True)
|
||||
|
||||
|
||||
@@ -3,12 +3,22 @@ from profiles.models import Profile
|
||||
|
||||
|
||||
def index(request):
|
||||
"""
|
||||
Display the list of all profiles
|
||||
:param request: None
|
||||
:return: render and display template as HTML
|
||||
"""
|
||||
profiles_list = Profile.objects.all()
|
||||
context = {'profiles_list': profiles_list}
|
||||
return render(request, 'profiles/index.html', context)
|
||||
|
||||
|
||||
def profile(request, username):
|
||||
"""
|
||||
Display the detail of a give profile
|
||||
:param request: None
|
||||
:return: render and display template as HTML
|
||||
"""
|
||||
profile = Profile.objects.get(user__username=username)
|
||||
context = {'profile': profile}
|
||||
return render(request, 'profiles/profile.html', context)
|
||||
|
||||
Reference in New Issue
Block a user