Closed abdulhamidbabawale closed 1 month ago
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.
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:
userid
field has been changed to a OneToOneField
to ensure that each user has exactly one profile.instagram
, linkedin
, facebook
, and twitter
, allow more comprehensive user profiles.additional_social_link
has been added to accommodate extra social media links beyond the predefined fields.To streamline property management and sale tracking, several changes have been made to the Property
model:
sellerid
field has been renamed to seller
for clarity.city
and address
fields have been added, making property information more detailed and complete.is_sold
boolean field has been introduced to indicate whether a property has been sold.is_sold = True
) are now directly associated with the SoldProperties
model.To accurately reflect the sale of properties, the SoldProperties
model has been enhanced:
userid
field has been renamed to buyerid
, clearly identifying the user who purchased the property.date_sold
field has been added to record when the property was sold.is_sold = True
), ensuring that only properties with completed transactions are tracked.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
company_logo
company_banner
instagram
linkedin
facebook
twitter
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
name
state
city
is_sold
date_sold
removedclass 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)
status
> rate
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)
this is to add new fields and fix mistakes in the models