Skip to content

Commit

Permalink
[Update] - Added more fields for properties + landlord. Added more mo…
Browse files Browse the repository at this point in the history
…dels: students + reviews
  • Loading branch information
mojalefakodisang committed Jun 14, 2024
1 parent 851fca7 commit 09075b2
Show file tree
Hide file tree
Showing 139 changed files with 639 additions and 47 deletions.
Binary file modified backend/__pycache__/manage.cpython-310.pyc
Binary file not shown.
Binary file removed backend/amenities/__pycache__/__init__.cpython-310.pyc
Binary file not shown.
Binary file removed backend/amenities/__pycache__/admin.cpython-310.pyc
Binary file not shown.
Binary file removed backend/amenities/__pycache__/apps.cpython-310.pyc
Binary file not shown.
Binary file removed backend/amenities/__pycache__/models.cpython-310.pyc
Binary file not shown.
Binary file removed backend/amenities/__pycache__/urls.cpython-310.pyc
Binary file not shown.
Binary file not shown.
File renamed without changes.
Binary file added backend/api/__pycache__/__init__.cpython-310.pyc
Binary file not shown.
File renamed without changes.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@

class AmenitiesConfig(AppConfig):
default_auto_field = 'django.db.models.BigAutoField'
name = 'amenities'
name = 'api.amenities'
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# Generated by Django 5.0.6 on 2024-06-14 01:04

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('amenities', '0002_amenity_property'),
]

operations = [
migrations.RemoveField(
model_name='amenity',
name='property',
),
migrations.AddField(
model_name='amenity',
name='description',
field=models.TextField(blank=True, null=True),
),
]
File renamed without changes.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
from django.db import models
from properties.models import Property


class Amenity(models.Model):
name = models.CharField(max_length=255, unique=True)
property = models.ForeignKey(Property, on_delete=models.CASCADE, related_name='amenities', null=True, blank=True)
description = models.TextField(blank=True, null=True)

def __str__(self):
return self.name
File renamed without changes.
File renamed without changes.
File renamed without changes.
4 changes: 2 additions & 2 deletions backend/amenities/views.py → backend/api/amenities/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
import jwt
from .models import Amenity
from rest_framework import status
from landlords.views import UserAuth
from landlords.models import Landlord
from api.landlords.views import UserAuth
from api.landlords.models import Landlord
from rest_framework.views import APIView
from .serializers import AmenitySerializer
from rest_framework.response import Response
Expand Down
File renamed without changes.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@

class LandlordsConfig(AppConfig):
default_auto_field = 'django.db.models.BigAutoField'
name = 'landlords'
name = 'api.landlords'
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
# Generated by Django 5.0.6 on 2024-06-14 00:47

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('landlords', '0002_remove_landlord_name'),
]

operations = [
migrations.AddField(
model_name='landlord',
name='company_address',
field=models.CharField(blank=True, max_length=255, null=True),
),
migrations.AddField(
model_name='landlord',
name='company_name',
field=models.CharField(blank=True, max_length=255, null=True),
),
migrations.AddField(
model_name='landlord',
name='date_of_birth',
field=models.DateField(blank=True, null=True),
),
migrations.AddField(
model_name='landlord',
name='gender',
field=models.CharField(blank=True, max_length=10, null=True),
),
migrations.AddField(
model_name='landlord',
name='phone_number',
field=models.CharField(blank=True, max_length=20, null=True),
),
migrations.AddField(
model_name='landlord',
name='street_address',
field=models.CharField(blank=True, max_length=255, null=True),
),
migrations.AlterField(
model_name='landlord',
name='is_active',
field=models.BooleanField(default=True),
),
]
File renamed without changes.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
26 changes: 26 additions & 0 deletions backend/api/landlords/models.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
from django.db import models
from django.contrib.auth.models import AbstractUser


class Landlord(AbstractUser):

# Basic information
username = None
email = models.EmailField(unique=True)
password = models.CharField(max_length=255)
phone_number = models.CharField(max_length=20, null=True, blank=True)
date_of_birth = models.DateField(null=True, blank=True)
gender = models.CharField(max_length=10, null=True, blank=True)

# Address
street_address = models.CharField(max_length=255, null=True, blank=True)

# Company
company_name = models.CharField(max_length=255, null=True, blank=True)
company_address = models.CharField(max_length=255, null=True, blank=True)

# Metadata
is_active = models.BooleanField(default=True)

USERNAME_FIELD = 'email'
REQUIRED_FIELDS = []
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@

class PropertiesConfig(AppConfig):
default_auto_field = 'django.db.models.BigAutoField'
name = 'properties'
name = 'api.properties'
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
# Generated by Django 5.0.6 on 2024-06-14 01:04

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('amenities', '0003_remove_amenity_property_amenity_description'),
('properties', '0004_property_latitude_property_longitude'),
]

operations = [
migrations.AddField(
model_name='property',
name='amenities',
field=models.ManyToManyField(blank=True, to='amenities.amenity'),
),
migrations.AddField(
model_name='property',
name='available_rooms',
field=models.PositiveIntegerField(default=1),
),
migrations.AddField(
model_name='property',
name='bathrooms',
field=models.PositiveIntegerField(default=1),
),
migrations.AddField(
model_name='property',
name='bedrooms',
field=models.PositiveIntegerField(default=1),
),
migrations.AddField(
model_name='property',
name='description',
field=models.TextField(blank=True, null=True),
),
migrations.AddField(
model_name='property',
name='first_deposit',
field=models.DecimalField(blank=True, decimal_places=2, max_digits=10, null=True),
),
migrations.AddField(
model_name='property',
name='main_image',
field=models.ImageField(blank=True, null=True, upload_to='property_images/'),
),
migrations.AddField(
model_name='property',
name='monthly_deposit',
field=models.DecimalField(blank=True, decimal_places=2, max_digits=10, null=True),
),
migrations.AddField(
model_name='property',
name='pets_allowed',
field=models.BooleanField(default=False),
),
migrations.AddField(
model_name='property',
name='property_type',
field=models.CharField(blank=True, max_length=100, null=True),
),
migrations.AddField(
model_name='property',
name='status',
field=models.CharField(default='available', max_length=20),
),
migrations.AddField(
model_name='property',
name='virtual_tour_link',
field=models.URLField(blank=True, null=True),
),
]
Empty file.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
40 changes: 40 additions & 0 deletions backend/api/properties/models.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
from django.db import models
from .utils import geocode_address
from api.landlords.models import Landlord
from api.amenities.models import Amenity

# Create your models here.
class Property(models.Model):
# Basic information
name = models.CharField(max_length=255)
street_address = models.CharField(max_length=255)
nearest_campus = models.CharField(max_length=255)
latitude = models.FloatField(null=True, blank=True)
longitude = models.FloatField(null=True, blank=True)
landlord = models.ForeignKey(Landlord, on_delete=models.CASCADE, related_name='properties')
amenities = models.ManyToManyField(Amenity, blank=True)

# Finances
first_deposit = models.DecimalField(max_digits=10, decimal_places=2, blank=True, null=True)
monthly_deposit = models.DecimalField(max_digits=10, decimal_places=2, blank=True, null=True)

# More information
description = models.TextField(blank=True, null=True)
property_type = models.CharField(max_length=100, blank=True, null=True)
bedrooms = models.PositiveIntegerField(default=1)
bathrooms = models.PositiveIntegerField(default=1)
available_rooms = models.PositiveIntegerField(default=1)
status = models.CharField(max_length=20, default='available')
pets_allowed = models.BooleanField(default=False)
main_image = models.ImageField(upload_to='property_images/', blank=True, null=True)
virtual_tour_link = models.URLField(blank=True, null=True)

def save(self, *args, **kwargs):
location = geocode_address(self.street_address)
if location:
self.latitude = location['lat']
self.longitude = location['lng']
super(Property, self).save(*args, **kwargs)

def __str__(self):
return self.name
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
from rest_framework import status
from .utils import geocode_address
from django.shortcuts import render
from landlords.models import Landlord
from api.landlords.models import Landlord
from rest_framework.views import APIView
from .serializers import PropertySerializer
from rest_framework.response import Response
Expand Down
Empty file added backend/api/reviews/__init__.py
Empty file.
Binary file not shown.
Binary file not shown.
Binary file added backend/api/reviews/__pycache__/apps.cpython-310.pyc
Binary file not shown.
Binary file not shown.
3 changes: 3 additions & 0 deletions backend/api/reviews/admin.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
from django.contrib import admin

# Register your models here.
6 changes: 6 additions & 0 deletions backend/api/reviews/apps.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
from django.apps import AppConfig


class ReviewsConfig(AppConfig):
default_auto_field = 'django.db.models.BigAutoField'
name = 'api.reviews'
25 changes: 25 additions & 0 deletions backend/api/reviews/migrations/0001_initial.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# Generated by Django 5.0.6 on 2024-06-14 01:51

import django.db.models.deletion
from django.db import migrations, models


class Migration(migrations.Migration):

initial = True

dependencies = [
('properties', '0005_property_amenities_property_available_rooms_and_more'),
]

operations = [
migrations.CreateModel(
name='Review',
fields=[
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('rating', models.PositiveIntegerField(default=0)),
('created_at', models.DateTimeField(auto_now_add=True)),
('property', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='properties.property')),
],
),
]
22 changes: 22 additions & 0 deletions backend/api/reviews/migrations/0002_initial.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# Generated by Django 5.0.6 on 2024-06-14 01:51

import django.db.models.deletion
from django.db import migrations, models


class Migration(migrations.Migration):

initial = True

dependencies = [
('reviews', '0001_initial'),
('students', '0001_initial'),
]

operations = [
migrations.AddField(
model_name='review',
name='user',
field=models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='students.student'),
),
]
Empty file.
Binary file not shown.
Binary file not shown.
Binary file not shown.
13 changes: 13 additions & 0 deletions backend/api/reviews/models.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
from django.db import models
from api.students.models import Student
from api.properties.models import Property


class Review(models.Model):
user = models.ForeignKey(Student, on_delete=models.CASCADE)
property = models.ForeignKey(Property, on_delete=models.CASCADE)
rating = models.PositiveIntegerField(default=0)
created_at = models.DateTimeField(auto_now_add=True)

def __str__(self):
return f'Review by {self.user.email} for {self.property.name}'
3 changes: 3 additions & 0 deletions backend/api/reviews/tests.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
from django.test import TestCase

# Create your tests here.
Empty file added backend/api/reviews/views.py
Empty file.
Empty file.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
3 changes: 3 additions & 0 deletions backend/api/students/admin.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
from django.contrib import admin

# Register your models here.
6 changes: 6 additions & 0 deletions backend/api/students/apps.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
from django.apps import AppConfig


class StudentsConfig(AppConfig):
default_auto_field = 'django.db.models.BigAutoField'
name = 'api.students'
Loading

0 comments on commit 09075b2

Please sign in to comment.