Skip to content

Commit

Permalink
Adding feat and race to the endpoints
Browse files Browse the repository at this point in the history
  • Loading branch information
BuildTools committed Aug 13, 2023
1 parent 710f7d1 commit faed207
Show file tree
Hide file tree
Showing 8 changed files with 113 additions and 15 deletions.
15 changes: 6 additions & 9 deletions api_v2/admin.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,6 @@
from django.contrib import admin

from api_v2.models import Weapon
from api_v2.models import Armor
from api_v2.models import Item, ItemSet

from api_v2.models import Document
from api_v2.models import License
from api_v2.models import Publisher
from api_v2.models import Ruleset
from api_v2.models import *


# Register your models here.
Expand All @@ -17,14 +10,18 @@ class FromDocumentModelAdmin(admin.ModelAdmin):


class ItemModelAdmin(admin.ModelAdmin):
list_display = ['key','category','name']
list_display = ['key', 'category', 'name']

admin.site.register(Weapon, admin_class=FromDocumentModelAdmin)
admin.site.register(Armor, admin_class=FromDocumentModelAdmin)

admin.site.register(Item, admin_class=ItemModelAdmin)
admin.site.register(ItemSet, admin_class=FromDocumentModelAdmin)

admin.site.register(Race, admin_class=FromDocumentModelAdmin)
admin.site.register(Trait)
admin.site.register(Feat, admin_class=FromDocumentModelAdmin)

admin.site.register(Document)
admin.site.register(License)
admin.site.register(Publisher)
Expand Down
27 changes: 27 additions & 0 deletions api_v2/migrations/0002_feat.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# Generated by Django 3.2.20 on 2023-08-13 01:53

from django.db import migrations, models
import django.db.models.deletion


class Migration(migrations.Migration):

dependencies = [
('api_v2', '0001_initial'),
]

operations = [
migrations.CreateModel(
name='Feat',
fields=[
('name', models.CharField(help_text='Name of the item.', max_length=100)),
('desc', models.TextField(help_text='Description of the game content item. Markdown.')),
('prerequisite_desc', models.CharField(help_text='Prerequisite for the game content item.', max_length=100)),
('key', models.CharField(help_text='Unique key for the Item.', max_length=100, primary_key=True, serialize=False)),
('document', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='api_v2.document')),
],
options={
'verbose_name_plural': 'feats',
},
),
]
39 changes: 39 additions & 0 deletions api_v2/migrations/0003_race_trait.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
# Generated by Django 3.2.20 on 2023-08-13 02:16

from django.db import migrations, models
import django.db.models.deletion


class Migration(migrations.Migration):

dependencies = [
('api_v2', '0002_feat'),
]

operations = [
migrations.CreateModel(
name='Race',
fields=[
('name', models.CharField(help_text='Name of the item.', max_length=100)),
('desc', models.TextField(help_text='Description of the game content item. Markdown.')),
('key', models.CharField(help_text='Unique key for the Item.', max_length=100, primary_key=True, serialize=False)),
('document', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='api_v2.document')),
('subrace_of', models.ForeignKey(null=True, on_delete=django.db.models.deletion.CASCADE, to='api_v2.race')),
],
options={
'verbose_name_plural': 'races',
},
),
migrations.CreateModel(
name='Trait',
fields=[
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('name', models.CharField(help_text='Name of the item.', max_length=100)),
('desc', models.TextField(help_text='Description of the game content item. Markdown.')),
('race', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='api_v2.race')),
],
options={
'abstract': False,
},
),
]
12 changes: 9 additions & 3 deletions api_v2/models/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@
The initialization for models for open5e's api v2.
"""

from .abstracts import HasName
from .abstracts import HasDescription
from .abstracts import Object
#from .abstracts import HasName
#from .abstracts import HasDescription
#from .abstracts import Object


from .item import Item
from .item import ItemSet
Expand All @@ -13,6 +14,11 @@

from .weapon import Weapon

from .race import Trait
from .race import Race

from .feat import Feat

from .document import Document
from .document import License
from .document import Publisher
Expand Down
6 changes: 3 additions & 3 deletions api_v2/models/race.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ class Trait(HasName, HasDescription):
Each trait ties to an individual race or subrace.
"""

race = models.ForeignKey('Race')
race = models.ForeignKey('Race', on_delete=models.CASCADE)


class Race(HasName, HasDescription, FromDocument):
Expand All @@ -22,12 +22,12 @@ class Race(HasName, HasDescription, FromDocument):
This model can be used to represent races based on parent=null.
"""

subrace_of = models.ForeignKey('self', null=True)
subrace_of = models.ForeignKey('self', null=True, on_delete=models.CASCADE)

@property
def is_subrace(self):
"""Returns whether the object is a subrace."""
return self.parent == null
return self.subrace_of != null

class Meta:
"""To assist with the UI layer."""
Expand Down
8 changes: 8 additions & 0 deletions api_v2/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,3 +118,11 @@ class ItemSetSerializer(GameContentSerializer):
class Meta:
model = models.ItemSet
fields = '__all__'


class FeatSerializer(GameContentSerializer):
key = serializers.ReadOnlyField()

class Meta:
model = models.feat
fields = '__all__'
20 changes: 20 additions & 0 deletions api_v2/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -163,3 +163,23 @@ class ArmorViewSet(viewsets.ReadOnlyModelViewSet):
queryset = models.Armor.objects.all().order_by('pk')
serializer_class = serializers.ArmorSerializer
filterset_class = ArmorFilterSet


class FeatFilterSet(FilterSet):
class Meta:
model = models.Feat
fields = {
'key': ['in', 'iexact', 'exact' ],
'name': ['iexact', 'exact'],
'document__key': ['in','iexact','exact'],
}


class FeatViewSet(viewsets.ReadOnlyModelViewSet):
"""
list: API endpoint for returning a list of feats.
retrieve: API endpoint for returning a particular feat.
"""
queryset = models.Feat.objects.all().order_by('pk')
serializer_class = serializers.FeatSerializer
filterset_class = FeatFilterSet
1 change: 1 addition & 0 deletions server/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@
router_v2.register(r'weapons',views_v2.WeaponViewSet)
router_v2.register(r'armor',views_v2.ArmorViewSet)
router_v2.register(r'rulesets',views_v2.RulesetViewSet)
router_v2.register(r'feats',views_v2.FeatViewSet)

# Wire up our API using automatic URL routing.
# Additionally, we include login URLs for the browsable API.
Expand Down

0 comments on commit faed207

Please sign in to comment.