import datetime from django.contrib.gis.db import models from utils.util import render_images, markdown_to_html PLANT_FAMILY = ( (0, 'Tomatoes'), (1, 'Cucumbers'), (2, 'Watermelons'), (3, 'Pumkins'), (4, 'Cantelope'), (5, 'Kale'), (6, 'Okra'), (7, 'Collards'), (8, 'Arugula'), (9, 'Butter Lettuce'), (10, 'Basil'), (11, 'Lemongrass'), (12, 'Thyme'), (13, 'Mint'), ) class Plant(models.Model): name = models.CharField(max_length=200) family = models.IntegerField(choices=PLANT_FAMILY, default=0) scientific_name = models.CharField(max_length=200, null=True, blank=True) edible = models.BooleanField(default=False) date_created = models.DateTimeField(default=datetime.datetime.now) growth_time = models.PositiveIntegerField() germination_time = models.PositiveIntegerField() seperation = models.PositiveIntegerField() notes = models.TextField(null=True, blank=True) CONDITIONS = ( (0, 'Direct Sun'), (1, 'Part Sun'), (2, 'Shade'), ) conditions = models.IntegerField(choices=CONDITIONS, default=0) PLANT_TYPE= ( (0, 'Vegetable'), (1, 'Herb'), (2, 'Berry'), (3, 'Nut'), ) conditions = models.IntegerField(choices=PLANT_TYPE, default=0) organic = models.BooleanField(default=True) heirloom = models.BooleanField(default=True) annual = models.BooleanField(default=True) class Meta: ordering = ('-date_created',) get_latest_by = 'date_created' def __str__(self): return self.name class Seed(models.Model): plant = models.ForeignKey(Plant, on_delete=models.CASCADE) brand = models.CharField(max_length=200) date_created = models.DateTimeField(default=datetime.datetime.now) estimated_growth_time = models.PositiveIntegerField() estimated_germination_time = models.PositiveIntegerField() organic = models.BooleanField(default=True) notes = models.TextField(null=True, blank=True) class Meta: ordering = ('-date_created',) get_latest_by = 'date_created' def __str__(self): return self.plant.name class Planting(models.Model): plant = models.ForeignKey(Plant, on_delete=models.CASCADE) number_of_plants = models.PositiveIntegerField() seed = models.ForeignKey(Seed, on_delete=models.CASCADE, null=True, blank=True) START_AREA = ( (0, 'Indoors'), (1, 'Direct Sow'), (2, 'Greenhouse'), (2, 'Purchased Seedling'), ) seed_start_area = models.IntegerField(choices=START_AREA, default=0) date_seed_started = models.DateField(null=True, blank=True) date_seed_sprouted = models.DateField(null=True, blank=True) date_hardened_off = models.DateField(null=True, blank=True) date_planted = models.DateField() GARDEN_PLOT = ( (0, 'Far Plot Mound'), (1, 'Far Plot ground'), (2, 'Herb Plot ground'), (2, 'Herb Plot bed'), ) garden_area = models.IntegerField(choices=GARDEN_PLOT, default=0) OUTCOME = ( (0, 'Unknown'), (1, 'Success'), (2, 'Moderate Success'), (3, 'Fail'), ) outcome = models.IntegerField(choices=OUTCOME, default=0) notes = models.TextField(null=True, blank=True) class Meta: ordering = ('-date_seed_started',) get_latest_by = 'date_seed_started' def __str__(self): return self.plant.name @property def get_previous_admin_url(self): n = self.get_previous_by_pub_date() return reverse('admin:%s_%s_change' %(self._meta.app_label, self._meta.model_name), args=[n.id] ) @property def get_next_admin_url(self): model = apps.get_model(app_label=self._meta.app_label, model_name=self._meta.model_name) try: return reverse('admin:%s_%s_change' %(self._meta.app_label, self._meta.model_name), args=[self.get_next_by_pub_date().pk] ) except model.DoesNotExist: return '' @property def family(self): return self.plant.get_family_display() def save(self, *args, **kwargs): created = self.pk is None if not created: md = render_images(self.notes) self.body_html = markdown_to_html(md) super(Planting, self).save(*args, **kwargs) class Guild(models.Model): name = models.CharField(max_length=200, blank=True) plant = models.ManyToManyField(Plant) seperation = models.PositiveIntegerField() notes = models.TextField(null=True, blank=True) def __str__(self): return self.name