124 lines
4 KiB
Python
124 lines
4 KiB
Python
from django.db import models
|
|
|
|
|
|
class Location(models.Model):
|
|
name = models.CharField(max_length=200, unique=True)
|
|
cover_photo = models.ImageField(upload_to='locations/', blank=True, null=True)
|
|
|
|
class Meta:
|
|
ordering = ['name']
|
|
|
|
def __str__(self):
|
|
return self.name
|
|
|
|
|
|
class Species(models.Model):
|
|
common_name = models.CharField(max_length=200)
|
|
scientific_name = models.CharField(max_length=200, blank=True)
|
|
description = models.TextField(blank=True)
|
|
watering = models.CharField(max_length=100, blank=True)
|
|
sunlight = models.CharField(max_length=200, blank=True)
|
|
shadow_tolerance = models.CharField(max_length=100, blank=True)
|
|
max_height_cm = models.PositiveIntegerField(null=True, blank=True)
|
|
growth_rate = models.CharField(max_length=100, blank=True)
|
|
growth_season = models.CharField(max_length=100, blank=True)
|
|
pruning_months = models.JSONField(default=list)
|
|
bloom_months = models.JSONField(default=list)
|
|
api_image_url = models.URLField(blank=True)
|
|
frost_hardiness_c = models.SmallIntegerField(null=True, blank=True)
|
|
planting_density_m2 = models.PositiveSmallIntegerField(null=True, blank=True)
|
|
perenual_id = models.IntegerField(unique=True, null=True, blank=True)
|
|
vpc_slug = models.CharField(max_length=200, blank=True, db_index=True)
|
|
vpc_raw = models.JSONField(null=True, blank=True)
|
|
|
|
class Meta:
|
|
ordering = ['common_name']
|
|
verbose_name_plural = 'species'
|
|
|
|
def __str__(self):
|
|
return self.common_name
|
|
|
|
|
|
WATERING_CHOICES = [
|
|
('frequent', '💧💧 Frequent'),
|
|
('regular', '💧 Regular'),
|
|
('minimum', '🌿 Minimum'),
|
|
('drought', '🌵 Drought tolerant'),
|
|
]
|
|
|
|
SUNLIGHT_CHOICES = [
|
|
('full_sun', '☀️ Full sun'),
|
|
('part_sun', '🌤 Part sun'),
|
|
('full_shade', '🌑 Full shade'),
|
|
]
|
|
|
|
|
|
class Plant(models.Model):
|
|
name = models.CharField(max_length=200)
|
|
species = models.ForeignKey(
|
|
Species, null=True, blank=True,
|
|
on_delete=models.SET_NULL, related_name='plants',
|
|
)
|
|
location = models.ForeignKey(
|
|
Location, null=True, blank=True,
|
|
on_delete=models.SET_NULL, related_name='plants',
|
|
)
|
|
is_indoor = models.BooleanField(default=False)
|
|
watering = models.CharField(max_length=100, blank=True, choices=WATERING_CHOICES)
|
|
sunlight = models.CharField(max_length=200, blank=True, choices=SUNLIGHT_CHOICES)
|
|
pruning_months = models.JSONField(default=list)
|
|
bloom_months = models.JSONField(default=list)
|
|
photo = models.ImageField(upload_to='plants/', blank=True)
|
|
notes = models.TextField(blank=True)
|
|
date_added = models.DateField(auto_now_add=True)
|
|
|
|
class Meta:
|
|
ordering = ['name']
|
|
|
|
def __str__(self):
|
|
return self.name
|
|
|
|
@property
|
|
def thumbnail_url(self):
|
|
thumb = self.photos.filter(is_thumbnail=True).first()
|
|
if thumb:
|
|
return thumb.image.url
|
|
first = self.photos.first()
|
|
if first:
|
|
return first.image.url
|
|
if self.photo:
|
|
return self.photo.url
|
|
return None
|
|
|
|
|
|
class PlantPhoto(models.Model):
|
|
plant = models.ForeignKey(Plant, on_delete=models.CASCADE, related_name='photos')
|
|
image = models.ImageField(upload_to='plants/photos/')
|
|
is_thumbnail = models.BooleanField(default=False)
|
|
uploaded_at = models.DateTimeField(auto_now_add=True)
|
|
|
|
class Meta:
|
|
ordering = ['uploaded_at']
|
|
|
|
|
|
class PlantCardPhoto(models.Model):
|
|
plant = models.ForeignKey(Plant, on_delete=models.CASCADE, related_name='card_photos')
|
|
image = models.ImageField(upload_to='plants/cards/')
|
|
uploaded_at = models.DateTimeField(auto_now_add=True)
|
|
|
|
class Meta:
|
|
ordering = ['uploaded_at']
|
|
|
|
|
|
class PruningLog(models.Model):
|
|
plant = models.ForeignKey(
|
|
Plant, on_delete=models.CASCADE, related_name='pruning_logs',
|
|
)
|
|
pruned_on = models.DateField()
|
|
notes = models.TextField(blank=True)
|
|
|
|
class Meta:
|
|
ordering = ['-pruned_on']
|
|
|
|
def __str__(self):
|
|
return f'{self.plant.name} pruned on {self.pruned_on}'
|