Advertisement
horozov86

models for my project

Mar 6th, 2024
485
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.74 KB | None | 0 0
  1. from django.db import models
  2. from django.contrib.auth.models import User
  3.  
  4. class Category(models.Model):
  5.     name = models.CharField(max_length=100)
  6.     description = models.TextField(blank=True)
  7.  
  8.     def __str__(self):
  9.         return self.name
  10.  
  11. class Place(models.Model):
  12.     name = models.CharField(max_length=200)
  13.     description = models.TextField()
  14.     location = models.CharField(max_length=200)
  15.     category = models.ForeignKey(Category, on_delete=models.CASCADE)
  16.     rating = models.FloatField(default=0)  # You can adjust this field to represent ratings
  17.  
  18.     def __str__(self):
  19.         return self.name
  20.  
  21. class Photo(models.Model):
  22.     place = models.ForeignKey(Place, related_name='photos', on_delete=models.CASCADE)
  23.     image = models.ImageField(upload_to='photos/')
  24.     description = models.TextField(blank=True)
  25.     uploaded_at = models.DateTimeField(auto_now_add=True)
  26.     user = models.ForeignKey(User, on_delete=models.CASCADE)
  27.  
  28.     def __str__(self):
  29.         return f"Photo of {self.place.name}"
  30.  
  31. class Review(models.Model):
  32.     place = models.ForeignKey(Place, related_name='reviews', on_delete=models.CASCADE)
  33.     user = models.ForeignKey(User, on_delete=models.CASCADE)
  34.     text = models.TextField()
  35.     rating = models.IntegerField()  # You can adjust this field to represent ratings
  36.     created_at = models.DateTimeField(auto_now_add=True)
  37.  
  38.     def __str__(self):
  39.         return f"Review of {self.place.name} by {self.user.username}"
  40.  
  41. class UserProfile(models.Model):
  42.     user = models.OneToOneField(User, on_delete=models.CASCADE)
  43.     bio = models.TextField(blank=True)
  44.     profile_picture = models.ImageField(upload_to='profile_pictures/', blank=True)
  45.  
  46.     def __str__(self):
  47.         return self.user.username
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement