1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
|
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
|