-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(zone): add zone models, admin, and some changes to other models (#…
…247) * feat(zone): add zone models, admin, and some changes to other models * fix(zone): fix weather ququery * fix(zone): tests
- Loading branch information
Showing
21 changed files
with
174 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
# Generated by Django 4.2 on 2023-05-01 08:04 | ||
|
||
from django.db import migrations, models | ||
import django.db.models.deletion | ||
|
||
|
||
class Migration(migrations.Migration): | ||
dependencies = [ | ||
("zones", "0001_initial"), | ||
("plants", "0009_alter_datapoint_options"), | ||
] | ||
|
||
operations = [ | ||
migrations.AddField( | ||
model_name="plant", | ||
name="zone", | ||
field=models.ForeignKey(null=True, on_delete=django.db.models.deletion.CASCADE, to="zones.zone"), | ||
), | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
# Generated by Django 4.2 on 2023-05-01 08:10 | ||
|
||
from django.db import migrations, models | ||
import django.db.models.deletion | ||
|
||
|
||
class Migration(migrations.Migration): | ||
dependencies = [ | ||
("zones", "0002_make_plant_zones"), | ||
("plants", "0010_plant_zone"), | ||
] | ||
|
||
operations = [ | ||
migrations.AlterField( | ||
model_name="plant", | ||
name="zone", | ||
field=models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to="zones.zone"), | ||
), | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
# Generated by Django 4.2 on 2023-05-01 13:04 | ||
|
||
from django.db import migrations | ||
|
||
|
||
class Migration(migrations.Migration): | ||
dependencies = [ | ||
("plants", "0011_alter_plant_zone"), | ||
] | ||
|
||
operations = [ | ||
migrations.RemoveField( | ||
model_name="plant", | ||
name="indoor", | ||
), | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
from django.contrib import admin | ||
|
||
from zones.models import Zone | ||
|
||
|
||
@admin.register(Zone) | ||
class ZoneAdmin(admin.ModelAdmin): | ||
pass |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
from django.apps import AppConfig | ||
|
||
|
||
class ZonesConfig(AppConfig): | ||
default_auto_field = "django.db.models.BigAutoField" | ||
name = "zones" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
# Generated by Django 4.2 on 2023-05-01 08:04 | ||
|
||
from django.conf import settings | ||
import django.contrib.gis.db.models.fields | ||
from django.db import migrations, models | ||
import django.db.models.deletion | ||
|
||
|
||
class Migration(migrations.Migration): | ||
initial = True | ||
|
||
dependencies = [ | ||
migrations.swappable_dependency(settings.AUTH_USER_MODEL), | ||
] | ||
|
||
operations = [ | ||
migrations.CreateModel( | ||
name="Zone", | ||
fields=[ | ||
("id", models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name="ID")), | ||
("name", models.CharField(max_length=256)), | ||
("location", django.contrib.gis.db.models.fields.PointField(srid=4326, blank=True, null=True)), | ||
("user", models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to=settings.AUTH_USER_MODEL)), | ||
], | ||
), | ||
migrations.AddIndex( | ||
model_name="zone", | ||
index=models.Index(fields=["location"], name="zone_location_idx"), | ||
), | ||
migrations.AddConstraint( | ||
model_name="zone", | ||
constraint=models.UniqueConstraint(fields=("user", "name"), name="unique_zone_name_for_user"), | ||
), | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
from django.db import migrations | ||
|
||
|
||
def set_plant_zone(apps, schema_editor): | ||
Zone = apps.get_model("zones", "Zone") | ||
Plant = apps.get_model("plants", "Plant") | ||
# Set the partners' region as the needs region as a default. | ||
for plant in Plant.objects.all(): | ||
if plant.indoor: | ||
zone = Zone.objects.get_or_create(user=plant.user, name="indoor") | ||
|
||
else: | ||
zone = Zone.objects.get_or_create(user=plant.user, name="outdoor") | ||
|
||
plant.zone = zone | ||
plant.save() | ||
|
||
|
||
class Migration(migrations.Migration): | ||
dependencies = [ | ||
("zones", "0001_initial"), | ||
("plants", "0010_plant_zone"), | ||
] | ||
|
||
operations = [ | ||
migrations.RunPython(set_plant_zone), | ||
] |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
from django.contrib.auth import get_user_model | ||
from django.db import models | ||
from django.contrib.gis.db import models as gis_models | ||
|
||
|
||
class Zone(models.Model): | ||
user = models.ForeignKey(get_user_model(), on_delete=models.CASCADE) | ||
name = models.CharField(max_length=256) | ||
location = gis_models.PointField(blank=True, null=True) | ||
|
||
def __str__(self): | ||
return self.name | ||
|
||
class Meta: | ||
constraints = [models.UniqueConstraint(fields=["user", "name"], name="unique_zone_name_for_user")] | ||
indexes = [models.Index(fields=["location"], name="zone_location_idx")] |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import factory | ||
from accounts.tests.factories import UserFactory | ||
from factory.django import DjangoModelFactory | ||
from zones import models | ||
|
||
|
||
class ZoneFactory(DjangoModelFactory): | ||
user = factory.SubFactory(UserFactory) | ||
name = factory.Sequence(lambda n: f"zone {n}") | ||
|
||
class Meta: | ||
model = models.Zone |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters