Skip to content

Commit b971234

Browse files
authored
Merge pull request #289 from American-Institutes-for-Research/HEA-1083/Add_other_livestock_production_strategy_type
Hea 1083/add other livestock production strategy type
2 parents 9e11f0b + 9313299 commit b971234

9 files changed

Lines changed: 212 additions & 0 deletions

File tree

apps/baseline/admin.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@
4747
MeatProduction,
4848
MilkProduction,
4949
OtherCashIncome,
50+
OtherLivestockProduction,
5051
OtherPurchase,
5152
PaymentInKind,
5253
ReliefGiftOther,
@@ -853,6 +854,13 @@ def get_queryset(self, request):
853854
return super().get_queryset(request).filter(strategy_type=LivelihoodStrategyType.LIVESTOCK_SALE)
854855

855856

857+
class OtherLivestockProductionInlineAdmin(LivelihoodActivityInlineAdmin):
858+
model = OtherLivestockProduction
859+
860+
def get_queryset(self, request):
861+
return super().get_queryset(request).filter(strategy_type=LivelihoodStrategyType.OTHER_LIVESTOCK_PRODUCTION)
862+
863+
856864
class CropProductionInlineAdmin(LivelihoodActivityInlineAdmin):
857865
model = CropProduction
858866

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
from django.db import migrations, models
2+
3+
4+
class Migration(migrations.Migration):
5+
6+
dependencies = [
7+
("baseline", "0037_livelihoodactivity_sort_key_wealthgroup_idx"),
8+
]
9+
10+
operations = [
11+
migrations.CreateModel(
12+
name="OtherLivestockProduction",
13+
fields=[],
14+
options={
15+
"verbose_name": "Other Livestock Production",
16+
"verbose_name_plural": "Other Livestock Production",
17+
"proxy": True,
18+
"indexes": [],
19+
"constraints": [],
20+
},
21+
bases=("baseline.livelihoodactivity",),
22+
),
23+
migrations.AlterField(
24+
model_name="livelihoodactivity",
25+
name="strategy_type",
26+
field=models.CharField(
27+
choices=[
28+
("MilkProduction", "Milk Production"),
29+
("ButterProduction", "Butter Production"),
30+
("MeatProduction", "Meat Production"),
31+
("LivestockSale", "Livestock Sale"),
32+
("OtherLivestockProduction", "Other Livestock Production"),
33+
("CropProduction", "Crop Production"),
34+
("FoodPurchase", "Food Purchase"),
35+
("PaymentInKind", "Payment in Kind"),
36+
("ReliefGiftOther", "Relief, Gift or Other Food"),
37+
("Hunting", "Hunting"),
38+
("Fishing", "Fishing"),
39+
("WildFoodGathering", "Wild Food Gathering"),
40+
("OtherCashIncome", "Other Cash Income"),
41+
("OtherPurchase", "Other Purchase"),
42+
],
43+
db_index=True,
44+
help_text="The type of livelihood strategy, such as crop production, or wild food gathering.",
45+
max_length=30,
46+
verbose_name="Strategy Type",
47+
),
48+
),
49+
migrations.AlterField(
50+
model_name="livelihoodstrategy",
51+
name="strategy_type",
52+
field=models.CharField(
53+
choices=[
54+
("MilkProduction", "Milk Production"),
55+
("ButterProduction", "Butter Production"),
56+
("MeatProduction", "Meat Production"),
57+
("LivestockSale", "Livestock Sale"),
58+
("OtherLivestockProduction", "Other Livestock Production"),
59+
("CropProduction", "Crop Production"),
60+
("FoodPurchase", "Food Purchase"),
61+
("PaymentInKind", "Payment in Kind"),
62+
("ReliefGiftOther", "Relief, Gift or Other Food"),
63+
("Hunting", "Hunting"),
64+
("Fishing", "Fishing"),
65+
("WildFoodGathering", "Wild Food Gathering"),
66+
("OtherCashIncome", "Other Cash Income"),
67+
("OtherPurchase", "Other Purchase"),
68+
],
69+
db_index=True,
70+
help_text="The type of livelihood strategy, such as crop production, or wild food gathering.",
71+
max_length=30,
72+
verbose_name="Strategy Type",
73+
),
74+
),
75+
]

apps/baseline/models.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2409,6 +2409,19 @@ class Meta:
24092409
proxy = True
24102410

24112411

2412+
class OtherLivestockProduction(LivelihoodActivity):
2413+
"""
2414+
Other livestock production by households in a Wealth Group, such as eggs, blood, skins, etc.
2415+
2416+
Stored on the BSS 'Data' worksheet in the 'Livestock Production' section.
2417+
"""
2418+
2419+
class Meta:
2420+
verbose_name = LivelihoodStrategyType.OTHER_LIVESTOCK_PRODUCTION.label
2421+
verbose_name_plural = LivelihoodStrategyType.OTHER_LIVESTOCK_PRODUCTION.label
2422+
proxy = True
2423+
2424+
24122425
class CropProduction(LivelihoodActivity):
24132426
"""
24142427
Production of crops by households in a Wealth Group for their own consumption, for sale and for other uses.

apps/baseline/serializers.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@
3939
MeatProduction,
4040
MilkProduction,
4141
OtherCashIncome,
42+
OtherLivestockProduction,
4243
OtherPurchase,
4344
PaymentInKind,
4445
ReliefGiftOther,
@@ -858,6 +859,12 @@ class Meta:
858859
fields = LivelihoodActivitySerializer.Meta.fields
859860

860861

862+
class OtherLivestockProductionSerializer(LivelihoodActivitySerializer):
863+
class Meta:
864+
model = OtherLivestockProduction
865+
fields = LivelihoodActivitySerializer.Meta.fields
866+
867+
861868
class CropProductionSerializer(LivelihoodActivitySerializer):
862869
class Meta:
863870
model = CropProduction

apps/baseline/tests/factories.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
MeatProduction,
3333
MilkProduction,
3434
OtherCashIncome,
35+
OtherLivestockProduction,
3536
OtherPurchase,
3637
PaymentInKind,
3738
ReliefGiftOther,
@@ -483,6 +484,22 @@ class Meta:
483484
percentage_kcals = None
484485

485486

487+
class OtherLivestockProductionFactory(LivelihoodActivityFactory):
488+
class Meta:
489+
model = OtherLivestockProduction
490+
django_get_or_create = [
491+
"livelihood_strategy",
492+
"livelihood_zone_baseline",
493+
"strategy_type",
494+
"scenario",
495+
"wealth_group",
496+
]
497+
498+
strategy_type = "OtherLivestockProduction"
499+
quantity_purchased = None
500+
expenditure = None
501+
502+
486503
class CropProductionFactory(LivelihoodActivityFactory):
487504
class Meta:
488505
model = CropProduction

apps/baseline/viewsets.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@
5555
MeatProduction,
5656
MilkProduction,
5757
OtherCashIncome,
58+
OtherLivestockProduction,
5859
OtherPurchase,
5960
PaymentInKind,
6061
ReliefGiftOther,
@@ -98,6 +99,7 @@
9899
MeatProductionSerializer,
99100
MilkProductionSerializer,
100101
OtherCashIncomeSerializer,
102+
OtherLivestockProductionSerializer,
101103
OtherPurchaseSerializer,
102104
PaymentInKindSerializer,
103105
ReliefGiftOtherSerializer,
@@ -1267,6 +1269,28 @@ class LivestockSaleViewSet(LivelihoodActivityViewSet):
12671269
filterset_class = LivestockSaleFilterSet
12681270

12691271

1272+
class OtherLivestockProductionFilterSet(LivelihoodActivityFilterSet):
1273+
class Meta(LivelihoodActivityFilterSet.Meta):
1274+
model = OtherLivestockProduction
1275+
1276+
1277+
class OtherLivestockProductionViewSet(LivelihoodActivityViewSet):
1278+
"""
1279+
API endpoint that allows other livestock production to be viewed or edited.
1280+
"""
1281+
1282+
queryset = OtherLivestockProduction.objects.select_related(
1283+
"livelihood_strategy__product",
1284+
"livelihood_strategy__season",
1285+
"livelihood_strategy__unit_of_measure",
1286+
"wealth_group__community__livelihood_zone_baseline__livelihood_zone__country",
1287+
"wealth_group__community__livelihood_zone_baseline__source_organization",
1288+
"wealth_group__wealth_group_category",
1289+
).order_by(*LIVELIHOOD_ACTIVITY_ORDER_BY)
1290+
serializer_class = OtherLivestockProductionSerializer
1291+
filterset_class = OtherLivestockProductionFilterSet
1292+
1293+
12701294
class CropProductionFilterSet(LivelihoodActivityFilterSet):
12711295
class Meta(LivelihoodActivityFilterSet.Meta):
12721296
model = CropProduction
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
from django.db import migrations, models
2+
3+
4+
class Migration(migrations.Migration):
5+
6+
dependencies = [
7+
("metadata", "0018_alter_seasonalactivitytype_activity_category"),
8+
]
9+
10+
operations = [
11+
migrations.AlterField(
12+
model_name="activitylabel",
13+
name="strategy_type",
14+
field=models.CharField(
15+
blank=True,
16+
choices=[
17+
("MilkProduction", "Milk Production"),
18+
("ButterProduction", "Butter Production"),
19+
("MeatProduction", "Meat Production"),
20+
("LivestockSale", "Livestock Sale"),
21+
("OtherLivestockProduction", "Other Livestock Production"),
22+
("CropProduction", "Crop Production"),
23+
("FoodPurchase", "Food Purchase"),
24+
("PaymentInKind", "Payment in Kind"),
25+
("ReliefGiftOther", "Relief, Gift or Other Food"),
26+
("Hunting", "Hunting"),
27+
("Fishing", "Fishing"),
28+
("WildFoodGathering", "Wild Food Gathering"),
29+
("OtherCashIncome", "Other Cash Income"),
30+
("OtherPurchase", "Other Purchase"),
31+
("LivestockProduction", "Livestock Production"),
32+
],
33+
help_text="The type of livelihood strategy, such as crop production, or wild food gathering.",
34+
max_length=30,
35+
verbose_name="Strategy Type",
36+
),
37+
),
38+
migrations.AlterField(
39+
model_name="season",
40+
name="purpose",
41+
field=models.CharField(
42+
blank=True,
43+
choices=[
44+
("MilkProduction", "Milk Production"),
45+
("ButterProduction", "Butter Production"),
46+
("MeatProduction", "Meat Production"),
47+
("LivestockSale", "Livestock Sale"),
48+
("OtherLivestockProduction", "Other Livestock Production"),
49+
("CropProduction", "Crop Production"),
50+
("FoodPurchase", "Food Purchase"),
51+
("PaymentInKind", "Payment in Kind"),
52+
("ReliefGiftOther", "Relief, Gift or Other Food"),
53+
("Hunting", "Hunting"),
54+
("Fishing", "Fishing"),
55+
("WildFoodGathering", "Wild Food Gathering"),
56+
("OtherCashIncome", "Other Cash Income"),
57+
("OtherPurchase", "Other Purchase"),
58+
],
59+
help_text="The Livelihood Strategy Type that this Season is relevant for.",
60+
max_length=30,
61+
null=True,
62+
verbose_name="Purpose",
63+
),
64+
),
65+
]

apps/metadata/models.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -193,6 +193,7 @@ class LivelihoodStrategyType(models.TextChoices):
193193
BUTTER_PRODUCTION = "ButterProduction", _("Butter Production")
194194
MEAT_PRODUCTION = "MeatProduction", _("Meat Production")
195195
LIVESTOCK_SALE = "LivestockSale", _("Livestock Sale")
196+
OTHER_LIVESTOCK_PRODUCTION = "OtherLivestockProduction", _("Other Livestock Production")
196197
CROP_PRODUCTION = "CropProduction", _("Crop Production")
197198
FOOD_PURCHASE = "FoodPurchase", _("Food Purchase")
198199
PAYMENT_IN_KIND = "PaymentInKind", _("Payment in Kind")

hea/urls.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@
4747
MeatProductionViewSet,
4848
MilkProductionViewSet,
4949
OtherCashIncomeViewSet,
50+
OtherLivestockProductionViewSet,
5051
OtherPurchaseViewSet,
5152
PaymentInKindViewSet,
5253
ReliefGiftOtherViewSet,
@@ -124,6 +125,7 @@
124125
router.register(r"butterproduction", ButterProductionViewSet)
125126
router.register(r"meatproduction", MeatProductionViewSet)
126127
router.register(r"livestocksale", LivestockSaleViewSet)
128+
router.register(r"otherlivestockproduction", OtherLivestockProductionViewSet)
127129
router.register(r"cropproduction", CropProductionViewSet)
128130
router.register(r"foodpurchase", FoodPurchaseViewSet)
129131
router.register(r"paymentinkind", PaymentInKindViewSet)

0 commit comments

Comments
 (0)