Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions venues/migrations/0003_alter_funeral_phone.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Generated by Django 5.0.7 on 2024-08-05 09:45

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('venues', '0002_alter_funeral_region'),
]

operations = [
migrations.AlterField(
model_name='funeral',
name='phone',
field=models.CharField(max_length=20),
),
]
27 changes: 27 additions & 0 deletions venues/migrations/0004_location_funeral_location.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# Generated by Django 5.0.7 on 2024-08-06 07:44

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


class Migration(migrations.Migration):

dependencies = [
('venues', '0003_alter_funeral_phone'),
]

operations = [
migrations.CreateModel(
name='Location',
fields=[
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('lat', models.FloatField(blank=True, null=True)),
('lng', models.FloatField(blank=True, null=True)),
],
),
migrations.AddField(
model_name='funeral',
name='location',
field=models.OneToOneField(blank=True, null=True, on_delete=django.db.models.deletion.CASCADE, to='venues.location'),
),
]
10 changes: 9 additions & 1 deletion venues/models.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,21 @@
from django.db import models

class Location(models.Model):
lat = models.FloatField(null=True, blank=True)
lng = models.FloatField(null=True, blank=True)

def __str__(self):
return f"Lat: {self.lat}, Lng: {self.lng}"

class Funeral(models.Model):
name = models.CharField(max_length=200, blank=False)
region = models.CharField(max_length=100, unique=False, blank=False)
address = models.CharField(max_length=300, unique=True, blank=False)
phone = models.CharField(max_length=20, unique=True, blank=False) # PhoneNumberField()라는 것도 있는데 일단 사용 안함
phone = models.CharField(max_length=20, blank=False) # PhoneNumberField()라는 것도 있는데 일단 사용 안함
image = models.ImageField(upload_to='funeral_images/', blank=True, null=True)
website = models.URLField(max_length=255, blank=True)
created_at = models.DateTimeField(auto_now_add=True)
location = models.OneToOneField(Location, on_delete=models.CASCADE, null=True, blank=True)

def __str__(self):
return self.name
17 changes: 15 additions & 2 deletions venues/serializers.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,20 @@
from rest_framework import serializers
from .models import Funeral
from .models import Funeral, Location

class LocationSerializer(serializers.ModelSerializer):
class Meta:
model = Location
fields = ['lat', 'lng']

class FuneralSerializer(serializers.ModelSerializer):
location = LocationSerializer()

class Meta:
model = Funeral
fields = '__all__'
fields = ['id', 'name', 'region', 'address', 'phone', 'image', 'website', 'created_at', 'location']

def create(self, validated_data):
location_data = validated_data.pop('location')
location = Location.objects.create(**location_data)
funeral = Funeral.objects.create(location=location, **validated_data)
return funeral