Фикс связей таблицы с друзьями

main
through-your-tears 9 months ago
parent 1752dff9b4
commit 77961345a8

@ -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]

@ -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')

@ -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')

Loading…
Cancel
Save