Skip to content

Commit

Permalink
Cria relacionamento entre places e systems
Browse files Browse the repository at this point in the history
  • Loading branch information
AlefMemTav committed Apr 1, 2024
1 parent c172d00 commit 8ec1c11
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 4 deletions.
19 changes: 19 additions & 0 deletions api/places/migrations/0006_room_systems.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# Generated by Django 4.2 on 2024-04-01 14:49

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('systems', '0001_initial'),
('places', '0005_alter_room_floor_alter_room_place'),
]

operations = [
migrations.AddField(
model_name='room',
name='systems',
field=models.ManyToManyField(to='systems.system'),
),
]
2 changes: 2 additions & 0 deletions api/places/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ class Room(models.Model):
name = models.CharField(max_length=50)
floor = models.IntegerField(default=0, validators=[MinValueValidator(0)])
place = models.ForeignKey(Place, related_name='rooms', on_delete=models.CASCADE)
systems = models.ManyToManyField('systems.System')




2 changes: 1 addition & 1 deletion api/places/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ class Meta:
class RoomSerializer(serializers.ModelSerializer):
class Meta:
model = Room
fields = ['id', 'name', 'floor', 'place_id']
fields = ['id', 'name', 'floor', 'place_id', 'systems']
extra_kwargs = {
'name': {'required': True},
'floor': {'required': True},
Expand Down
4 changes: 2 additions & 2 deletions api/places/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@
from rest_framework.routers import SimpleRouter

router = SimpleRouter()
router.register('places',PlaceViewSet)
router.register('rooms', RoomViewSet)
router.register(r'places',PlaceViewSet)
router.register(r'rooms', RoomViewSet)
3 changes: 2 additions & 1 deletion api/sigeie/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@
'django.contrib.staticfiles',
'rest_framework',
'users',
'places'
'places',
'systems'
]

MIDDLEWARE = [
Expand Down

0 comments on commit 8ec1c11

Please sign in to comment.