InternPulse / property-hive-backend

Property Hive API is a robust, RESTful web service designed to power real estate management applications. It provides a comprehensive set of endpoints that facilitate various operations essential to property management, user authentication, and financial tracking within the real estate industry.
https://documenter.getpostman.com/view/38661757/2sAXxMgDfr
0 stars 2 forks source link

updating the db models #15

Closed abdulhamidbabawale closed 1 month ago

abdulhamidbabawale commented 1 month ago

this is to add new fields and fix mistakes in the models

abdulhamidbabawale commented 1 month ago

Major Updates to Database Models for Property and Profile Management

Overview

i recently implemented a series of crucial updates to the database models in the property-hive-backend project. These changes are designed to improve the relationships between users, profiles, and properties, as well as enhance the overall structure for handling property transactions.

Detailed Changes

1. Profile Model Enhancements

Previously, the Profile model only allowed users to have a single profile with basic fields. To improve user representation, several new fields have been added:

2. Property Model Improvements

To streamline property management and sale tracking, several changes have been made to the Property model:

3. SoldProperties Model Adjustments

To accurately reflect the sale of properties, the SoldProperties model has been enhanced:

abdulhamidbabawale commented 1 month ago

Profile Model

class Profile(models.Model):
    userid = models.OneToOneField(User, on_delete=models.CASCADE, related_name='profile')
    company_logo = models.ImageField(upload_to='company_profiles/', blank=True, null=True)
    company_banner = models.ImageField(upload_to='company_profiles/', blank=True, null=True)
    company_address = models.CharField(max_length=255, blank=True, null=True)
    title = models.CharField(max_length=50, blank=True, null=True)
    description = models.TextField(max_length=500)
    instagram = models.CharField(max_length=225, blank=True, null=True)
    linkedin = models.CharField(max_length=225, blank=True, null=True)
    facebook = models.CharField(max_length=225, blank=True, null=True)
    twitter = models.CharField(max_length=225, blank=True, null=True)

added

abdulhamidbabawale commented 1 month ago

Property model

class Property(models.Model):
    sellerid = models.ForeignKey(User, on_delete=models.CASCADE, related_name='properties')
    name=models.CharField(max_length=100)
    state=models.CharField(max_length=255)
    city=models.CharField(max_length=255)
    address=models.CharField(max_length=255)
    description = models.CharField(max_length=255)
    squaremeters=models.CharField(max_length=255)
    property_type=models.CharField(max_length=255)
    price =models.IntegerField(null=False, blank=True)
    is_sold = models.BooleanField(default=False)
    date_sold = models.DateTimeField(null=True, blank=True)
    created_at=models.DateTimeField(auto_now_add=True)
    updated_at=models.DateTimeField(auto_now=True)

added

abdulhamidbabawale commented 1 month ago

ratings

class Rate(models.IntegerChoices):
    ONE_STAR = 1, '1 Star'
    TWO_STAR = 2, '2 Stars'
    THREE_STAR = 3, '3 Stars'
    FOUR_STAR = 4, '4 Stars'
    FIVE_STAR = 5, '5 Stars'
class Ratings(models.Model):
     userid = models.ForeignKey(User, on_delete=models.CASCADE, related_name='ratings')
     propertyid =  models.ForeignKey(Property, on_delete=models.CASCADE, related_name='propertyid_rating')
     comment=models.TextField( null=True)
     rate = models.IntegerField(
        choices=Rate.choices,
        default=Rate.ONE_STAR,
     )
     created_at=models.DateTimeField(auto_now_add=True)
     updated_at=models.DateTimeField(auto_now=True)
abdulhamidbabawale commented 1 month ago
class Soldproperties(models.Model):
    buyerid = models.ForeignKey(User, on_delete=models.CASCADE, related_name='user_soldproperties')
    propertyid = models.ForeignKey(Property, on_delete=models.CASCADE, related_name='property_soldproperties')
    date_sold=models.DateTimeField(auto_now_add=True)
    def clean(self):
        # Validate that the associated property is sold
        if not self.propertyid.is_sold:
            raise ValidationError("The property must be marked as sold to create a sale record.")

    def save(self, *args, **kwargs):
        self.clean()  # Call the clean method to enforce validation
        super().save(*args, **kwargs)