-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #164 from fga-eps-mds/feature/67-tree-registration
Cadastro de Árvore
- Loading branch information
Showing
26 changed files
with
1,132 additions
and
24 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
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
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 |
---|---|---|
@@ -1,12 +1,13 @@ | ||
from django.urls import path, include | ||
from .viewsets import PropertyViewSet | ||
from rest_framework.routers import DefaultRouter | ||
from rest_framework import routers | ||
|
||
router = DefaultRouter() | ||
router.register(r'', PropertyViewSet, base_name='property') | ||
|
||
app_name = 'property' | ||
|
||
urlpatterns = [ | ||
] | ||
router = routers.SimpleRouter() | ||
router.register(r'', PropertyViewSet, basename='property') | ||
|
||
urlpatterns += router.urls | ||
urlpatterns = [ | ||
path('<int:property_pk>/trees/', include('tree.urls')), | ||
] + router.urls |
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,5 @@ | ||
from django.contrib import admin | ||
from .models import Tree, HarvestMonth | ||
|
||
admin.site.register(Tree) | ||
admin.site.register(HarvestMonth) |
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,5 @@ | ||
from django.apps import AppConfig | ||
|
||
|
||
class TreeConfig(AppConfig): | ||
name = 'tree' |
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,41 @@ | ||
# Generated by Django 2.2.4 on 2019-11-11 10:58 | ||
|
||
from django.db import migrations, models | ||
import django.db.models.deletion | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
initial = True | ||
|
||
dependencies = [ | ||
('property', '0001_initial'), | ||
] | ||
|
||
operations = [ | ||
migrations.CreateModel( | ||
name='Tree', | ||
fields=[ | ||
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), | ||
('tree_type', models.CharField(choices=[('Avocado', 'Avocado'), ('Pineapple', 'Pineapple'), ('Banana', 'Banana'), ('Persimmon', 'Persimmon'), ('Coconut', 'Coconut'), ('FIG', 'FIG'), ('Guava', 'Guava'), ('Jabuticaba', 'Jabuticaba'), ('Orange', 'Orange'), ('Lemon', 'Lemon'), ('Apple', 'Apple'), ('Papaya', 'Papaya'), ('Mango', 'Mango'), ('Passion Fruit', 'Passion Fruit'), ('Quince', 'Quince'), ('Nectarine', 'Nectarine'), ('Loquat', 'Loquat'), ('Pear', 'Pear'), ('Pequizeiro', 'Pequizeiro'), ('Tangerine', 'Tangerine'), ('Peach', 'Peach'), ('Vine', 'Vine')], max_length=13, verbose_name='Tree of type')), | ||
('number_of_tree', models.IntegerField(default=1, verbose_name='Number of tree')), | ||
('tree_height', models.DecimalField(decimal_places=1, max_digits=3, verbose_name='Average tree height')), | ||
('property', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='trees', to='property.Property', verbose_name='Property trees')), | ||
], | ||
options={ | ||
'unique_together': {('property', 'tree_type')}, | ||
}, | ||
), | ||
migrations.CreateModel( | ||
name='HarvestMonth', | ||
fields=[ | ||
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), | ||
('harvest_month', models.CharField(choices=[('January', 'January'), ('February', 'February'), ('March', 'March'), ('April', 'April'), ('May', 'May'), ('June', 'June'), ('July', 'July'), ('August', 'August'), ('September', 'September'), ('October', 'October'), ('November', 'November'), ('December', 'December')], max_length=9, verbose_name='Harvest month')), | ||
('tree', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='harvest_months', to='tree.Tree')), | ||
], | ||
options={ | ||
'verbose_name_plural': 'Harvest Months', | ||
'unique_together': {('tree', 'harvest_month')}, | ||
}, | ||
), | ||
] |
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,118 @@ | ||
from django.db import models | ||
from django.utils.translation import ugettext as _ | ||
from property.models import Property | ||
|
||
|
||
class Tree(models.Model): | ||
|
||
class Meta: | ||
unique_together = ('property', 'tree_type') | ||
|
||
property = models.ForeignKey( | ||
Property, | ||
on_delete=models.CASCADE, | ||
verbose_name=_('Property trees'), | ||
related_name=_('trees'), | ||
) | ||
|
||
TYPE_OF_TREES = ( | ||
(_('Avocado'), _('Avocado')), | ||
(_('Pineapple'), _('Pineapple')), | ||
(_('Banana'), _('Banana')), | ||
(_('Persimmon'), _('Persimmon')), | ||
(_('Coconut'), _('Coconut')), | ||
(_('FIG'), _('FIG')), | ||
(_('Guava'), _('Guava')), | ||
(_('Jabuticaba'), _('Jabuticaba')), | ||
(_('Orange'), _('Orange')), | ||
(_('Lemon'), _('Lemon')), | ||
(_('Apple'), _('Apple')), | ||
(_('Papaya'), _('Papaya')), | ||
(_('Mango'), _('Mango')), | ||
(_('Passion Fruit'), _('Passion Fruit')), | ||
(_('Quince'), _('Quince')), | ||
(_('Nectarine'), _('Nectarine')), | ||
(_('Loquat'), _('Loquat')), | ||
(_('Pear'), _('Pear')), | ||
(_('Pequizeiro'), _('Pequizeiro')), | ||
(_('Tangerine'), _('Tangerine')), | ||
(_('Peach'), _('Peach')), | ||
(_('Vine'), _('Vine')), | ||
) | ||
|
||
tree_type = models.CharField( | ||
verbose_name=_('Tree of type'), | ||
choices=TYPE_OF_TREES, | ||
max_length=13, | ||
) | ||
|
||
number_of_tree = models.IntegerField( | ||
verbose_name=_('Number of tree'), | ||
default=1, | ||
) | ||
|
||
tree_height = models.DecimalField( | ||
verbose_name=_('Average tree height'), | ||
decimal_places=1, | ||
max_digits=3, | ||
) | ||
|
||
picture = models.ImageField(upload_to='static/trees', blank=True, | ||
null=True) | ||
|
||
def __str__(self): | ||
return (f"{self.pk}, " + | ||
f"{self.tree_type}, " + | ||
f"{self.number_of_tree}") | ||
|
||
@staticmethod | ||
def valid_tree_types(): | ||
""" | ||
This class method returns a list of valid address | ||
types | ||
""" | ||
return [k for k, v in Tree.TYPE_OF_TREES] | ||
|
||
|
||
class HarvestMonth(models.Model): | ||
class Meta: | ||
verbose_name_plural = _('Harvest Months') | ||
unique_together = ('tree', 'harvest_month') | ||
|
||
tree = models.ForeignKey( | ||
Tree, | ||
models.CASCADE, | ||
related_name=_('harvest_months'), | ||
) | ||
|
||
MONTHS = ( | ||
(_('January'), _('January')), | ||
(_('February'), _('February')), | ||
(_('March'), _('March')), | ||
(_('April'), _('April')), | ||
(_('May'), _('May')), | ||
(_('June'), _('June')), | ||
(_('July'), _('July')), | ||
(_('August'), _('August')), | ||
(_('September'), _('September')), | ||
(_('October'), _('October')), | ||
(_('November'), _('November')), | ||
(_('December'), _('December')), | ||
) | ||
|
||
harvest_month = models.CharField( | ||
choices=MONTHS, | ||
verbose_name=_('Harvest month'), | ||
max_length=9, | ||
) | ||
|
||
def __str__(self): | ||
return f'{self.harvest_month}' | ||
|
||
@staticmethod | ||
def valid_months(): | ||
""" | ||
This class method returns a list of valid address | ||
types | ||
""" | ||
return [k for k, v in HarvestMonth.MONTHS] |
Oops, something went wrong.