Skip to content

Commit a7d9c91

Browse files
Merge pull request open5e#573 from open5e/572-api-v2-weapon-model-not-returning-properties-field-when-access-as-a-foreignkey-via-items-endpoint
Fixing some accumulated bugs.
2 parents 730a662 + c3e6fc3 commit a7d9c91

8 files changed

+16080
-487
lines changed

api_v2/models/weapon.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -117,29 +117,29 @@ def is_martial(self):
117117
@property
118118
def is_melee(self):
119119
# Ammunition weapons can only be used as improvised melee weapons.
120-
return not self.ammunition
120+
return not self.requires_ammunition
121121

122122
@property
123123
def ranged_attack_possible(self):
124124
# Only ammunition or throw weapons can make ranged attacks.
125-
return self.ammunition or self.thrown
125+
return self.requires_ammunition or self.is_thrown
126126

127127
@property
128128
def range_melee(self):
129-
return self.range_reach
129+
return self.reach
130130

131131
@property
132132
def is_reach(self):
133133
# A weapon with a longer reach than the default has the reach property.
134-
return self.range_reach > 5
134+
return self.reach > 5
135135

136136
@property
137137
def properties(self):
138138
properties = []
139139

140140
range_desc = "(range {}/{})".format(
141-
str(self.range_normal),
142-
str(self.range_long))
141+
str(self.range),
142+
str(self.long_range))
143143

144144
versatile_desc = "({})".format(self.versatile_dice)
145145

api_v2/serializers/item.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,8 @@ class Meta:
4646
class ItemSerializer(GameContentSerializer):
4747
key = serializers.ReadOnlyField()
4848
is_magic_item = serializers.ReadOnlyField()
49+
weapon = WeaponSerializer(read_only=True, context={'request':{}})
50+
armor = ArmorSerializer(read_only=True, context={'request':{}})
4951

5052
class Meta:
5153
model = models.Item

api_v2/tests/responses/TestObjects.test_item_armor_example.approved.json

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,16 @@
11
{
2-
"armor": "http://localhost:8000/v2/armor/srd_splint/",
2+
"armor": {
3+
"ac_add_dexmod": false,
4+
"ac_base": 17,
5+
"ac_cap_dexmod": null,
6+
"ac_display": "17",
7+
"document": "http://localhost:8000/v2/documents/srd/",
8+
"grants_stealth_disadvantage": true,
9+
"key": "srd_splint",
10+
"name": "Splint",
11+
"strength_score_required": 15,
12+
"url": "http://localhost:8000/v2/armor/srd_splint/"
13+
},
314
"armor_class": 0,
415
"category": "http://localhost:8000/v2/itemcategories/armor/",
516
"cost": "200.00",

0 commit comments

Comments
 (0)