diff --git a/plants/forms.py b/plants/forms.py index e90bc64..a27d74d 100644 --- a/plants/forms.py +++ b/plants/forms.py @@ -1,5 +1,5 @@ from django import forms -from .models import Plant, PruningLog, Location +from .models import Plant, PruningLog, Location, WATERING_CHOICES, SUNLIGHT_CHOICES MONTH_CHOICES = [ ('1', 'Jan'), ('2', 'Feb'), ('3', 'Mar'), ('4', 'Apr'), @@ -27,10 +27,18 @@ class PlantForm(forms.ModelForm): label='Or add new location', widget=forms.TextInput(attrs={'class': 'form-control', 'placeholder': 'e.g. Living room'}), ) + watering = forms.ChoiceField( + choices=[('', '—')] + WATERING_CHOICES, + required=False, + ) + sunlight = forms.ChoiceField( + choices=[('', '—')] + SUNLIGHT_CHOICES, + required=False, + ) class Meta: model = Plant - fields = ['name', 'location', 'is_indoor', 'bloom_months', 'notes'] + fields = ['name', 'location', 'is_indoor', 'watering', 'sunlight', 'bloom_months', 'notes'] widgets = { 'notes': forms.Textarea(attrs={'rows': 3, 'class': 'form-control'}), 'name': forms.TextInput(attrs={'class': 'form-control'}), diff --git a/plants/migrations/0008_add_watering_sunlight_to_plant.py b/plants/migrations/0008_add_watering_sunlight_to_plant.py new file mode 100644 index 0000000..e749896 --- /dev/null +++ b/plants/migrations/0008_add_watering_sunlight_to_plant.py @@ -0,0 +1,23 @@ +# Generated by Django 5.2.1 on 2026-05-29 09:46 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('plants', '0007_plantcardphoto'), + ] + + operations = [ + migrations.AddField( + model_name='plant', + name='sunlight', + field=models.CharField(blank=True, max_length=200), + ), + migrations.AddField( + model_name='plant', + name='watering', + field=models.CharField(blank=True, max_length=100), + ), + ] diff --git a/plants/migrations/0009_update_watering_sunlight_choices.py b/plants/migrations/0009_update_watering_sunlight_choices.py new file mode 100644 index 0000000..243d743 --- /dev/null +++ b/plants/migrations/0009_update_watering_sunlight_choices.py @@ -0,0 +1,23 @@ +# Generated by Django 5.2.1 on 2026-05-29 09:53 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('plants', '0008_add_watering_sunlight_to_plant'), + ] + + operations = [ + migrations.AlterField( + model_name='plant', + name='sunlight', + field=models.CharField(blank=True, choices=[('full_sun', '☀️ Full sun'), ('part_sun', '🌤 Part sun'), ('full_shade', '🌑 Full shade')], max_length=200), + ), + migrations.AlterField( + model_name='plant', + name='watering', + field=models.CharField(blank=True, choices=[('frequent', '💧💧 Frequent'), ('regular', '💧 Regular'), ('minimum', '🌿 Minimum'), ('drought', '🌵 Drought tolerant')], max_length=100), + ), + ] diff --git a/plants/models.py b/plants/models.py index 234c3ec..9afa808 100644 --- a/plants/models.py +++ b/plants/models.py @@ -36,6 +36,20 @@ class Species(models.Model): 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( @@ -47,6 +61,8 @@ class Plant(models.Model): 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) diff --git a/plants/templates/plants/plant_detail.html b/plants/templates/plants/plant_detail.html index 85b8dbd..d60277c 100644 --- a/plants/templates/plants/plant_detail.html +++ b/plants/templates/plants/plant_detail.html @@ -28,12 +28,16 @@ {% if plant.location %}

📍 {{ plant.location.name }}

{% endif %} -{% if plant.species %} +{% if plant.watering or plant.sunlight or plant.species %}
- {% if plant.species.watering %} + {% if plant.watering %} + {{ plant.get_watering_display }} + {% elif plant.species.watering %} 💧 {{ plant.species.watering }} {% endif %} - {% if plant.species.sunlight %} + {% if plant.sunlight %} + {{ plant.get_sunlight_display }} + {% elif plant.species.sunlight %} ☀️ {{ plant.species.sunlight }} {% endif %} {% if plant.species.max_height_cm %} @@ -43,7 +47,8 @@ 🌱 {{ plant.species.growth_rate }} {% endif %}
-{% if plant.species.vpc_slug %} +{% endif %} +{% if plant.species and plant.species.vpc_slug %}
{% csrf_token %} @@ -55,7 +60,6 @@
{% endif %} -{% endif %} {% load plant_extras %} {% if plant.bloom_months %} diff --git a/plants/templates/plants/plant_form.html b/plants/templates/plants/plant_form.html index 82ea60c..0abeb41 100644 --- a/plants/templates/plants/plant_form.html +++ b/plants/templates/plants/plant_form.html @@ -45,6 +45,40 @@ +
+ +
+ {% for val, label in form.watering.field.choices %} +
+ + +
+ {% endfor %} +
+ {% if species and species.watering %}
Species default: 💧 {{ species.watering }}
{% endif %} + {% if form.watering.errors %}
{{ form.watering.errors }}
{% endif %} +
+ +
+ +
+ {% for val, label in form.sunlight.field.choices %} +
+ + +
+ {% endfor %} +
+ {% if species and species.sunlight %}
Species default: ☀️ {{ species.sunlight }}
{% endif %} + {% if form.sunlight.errors %}
{{ form.sunlight.errors }}
{% endif %} +
+