diff --git a/src/organizations/admin.py b/src/organizations/admin.py index 8c38f3f..0712ba9 100644 --- a/src/organizations/admin.py +++ b/src/organizations/admin.py @@ -1,3 +1,17 @@ from django.contrib import admin +from .models import Category, Location, Organization, OrganizationImage, Region + # Register your models here. + + +models = [Category, Location, OrganizationImage, Region] + +for model in models: + admin.site.register(model) + + +@admin.register(Organization) +class OrganizationAdmin(admin.ModelAdmin): + list_display = ['name', 'category', 'phone', 'website'] + inlines = [OrganizationImage] diff --git a/src/organizations/models.py b/src/organizations/models.py index 29a5a93..3db6288 100644 --- a/src/organizations/models.py +++ b/src/organizations/models.py @@ -8,26 +8,39 @@ class Region(models.Model): code = models.PositiveIntegerField() name = models.CharField(max_length=64) + def __str__(self): + return self.name + class Location(models.Model): coords = PointField(db_index=True) region = models.ForeignKey(Region, on_delete=models.SET_NULL, null=True) address = models.CharField(max_length=512, blank=True, null=True) + def __str__(self): + return str(self.coords) + class Category(models.Model): name = models.CharField(max_length=64) icon = models.ImageField(upload_to='icons/category/') + def __str__(self): + return self.name + class Organization(models.Model): location = models.ForeignKey(Location, on_delete=models.SET_NULL, null=True) name = models.CharField(max_length=256) phone = models.CharField(max_length=20) + category = models.ForeignKey(Category, on_delete=models.SET_NULL, null=True, default=None) website = models.URLField() description = models.TextField() owner = models.ForeignKey('jwtauth.CustomUser', on_delete=models.SET_NULL, null=True) + def __str__(self): + return self.name + class OrganizationImage(models.Model): image = models.ImageField(upload_to='images/organizations') diff --git a/src/organizations/serializers.py b/src/organizations/serializers.py index bd00c29..047a8d6 100644 --- a/src/organizations/serializers.py +++ b/src/organizations/serializers.py @@ -3,7 +3,7 @@ from rest_framework import serializers from core.fields import LocationField from jwtauth.serializers import CustomUserSerializer from .models import Category, Location, Organization, OrganizationImage -from .repositories import OrganizationImagesRepository +from .repositories import OrganizationImagesRepository, CategoryRepository class CategorySerializer(serializers.ModelSerializer): @@ -28,14 +28,15 @@ class OrganizationListSerializer(serializers.ModelSerializer): class Meta: model = Organization - fields = ('location', 'images', 'name', 'phone', 'description', 'website') + fields = ('location', 'images', 'name', 'phone', 'description', 'website', 'category') class OrganizationCreateSerializer(serializers.ModelSerializer): location = LocationSerializer() images = serializers.PrimaryKeyRelatedField(many=True, queryset=OrganizationImagesRepository) owner = serializers.StringRelatedField() + category = serializers.PrimaryKeyRelatedField(queryset=CategoryRepository.all()) class Meta: model = Organization - fields = ('location', 'images', 'name', 'phone', 'website', 'description', 'owner') + fields = ('location', 'images', 'name', 'phone', 'website', 'description', 'owner', 'category')