Skip to content

Commit

Permalink
feat: addresses #17, adds more control over Categories
Browse files Browse the repository at this point in the history
  • Loading branch information
erictheise committed Mar 23, 2020
1 parent 51957f4 commit 3003bae
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 3 deletions.
8 changes: 7 additions & 1 deletion mdi/admin.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# -*- coding: utf-8 -*-
from django.contrib.gis import admin
from accounts.models import SocialNetwork
from .models import Organization, OrganizationSocialNetwork, Tool, License, Pricing
from .models import Category, Organization, OrganizationSocialNetwork, Tool, License, Pricing
from django.db.models.functions import Lower


Expand All @@ -12,6 +12,11 @@


# Create Admin-related classes
@admin.register(Category)
class CategoryNetworkAdmin(admin.ModelAdmin):
list_display = ('name', 'description', )


class OrganizationSocialNetworkInline(admin.TabularInline):
model = OrganizationSocialNetwork
extra = 3
Expand Down Expand Up @@ -46,6 +51,7 @@ class LicenseAdmin(admin.ModelAdmin):
list_filter = ('spdx', )
search_fields = ['spdx', 'name', ]


@admin.register(Pricing)
class PricingAdmin(admin.ModelAdmin):
fields = ('name', )
23 changes: 23 additions & 0 deletions mdi/migrations/0037_auto_20200323_0409.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# Generated by Django 3.0.3 on 2020-03-23 04:09

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('mdi', '0036_tool_sectors'),
]

operations = [
migrations.AlterModelOptions(
name='category',
options={'ordering': ['order']},
),
migrations.AddField(
model_name='category',
name='order',
field=models.IntegerField(default=1),
preserve_default=False,
),
]
3 changes: 2 additions & 1 deletion mdi/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,12 @@
class Category(models.Model):
name = models.CharField(blank=False, max_length=255, unique=True)
description = models.CharField(blank=True, default='', max_length=255)
order = models.IntegerField()
created_at = models.DateTimeField(auto_now_add=True)
updated_at = models.DateTimeField(auto_now=True)

class Meta:
ordering = ['name']
ordering = ['order']

def __str__(self):
return self.name
Expand Down
12 changes: 11 additions & 1 deletion mdi/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,10 +58,20 @@ class ToolSerializer(serializers.HyperlinkedModelSerializer):
license = serializers.StringRelatedField(source='license.spdx')
pricing = serializers.StringRelatedField(source='pricing.name')
languages_supported = LanguageSerializer(many=True)
sectors = serializers.StringRelatedField(many=True)

class Meta:
model = Tool
fields = ('name', 'description', 'url', 'license', 'pricing', 'languages_supported', 'notes', )
fields = (
'name',
'description',
'url',
'license',
'pricing',
'languages_supported',
'sectors',
'notes',
)


class OrganizationSerializer(CountryFieldMixin, GeoFeatureModelSerializer):
Expand Down

0 comments on commit 3003bae

Please sign in to comment.