diff --git a/Dhackathon/db.sqlite3 b/Dhackathon/db.sqlite3 index e69de29b..30f05b73 100644 Binary files a/Dhackathon/db.sqlite3 and b/Dhackathon/db.sqlite3 differ diff --git a/Dhackathon/hackathon/__pycache__/settings.cpython-310.pyc b/Dhackathon/hackathon/__pycache__/settings.cpython-310.pyc index 04c37657..ea7b0a9e 100644 Binary files a/Dhackathon/hackathon/__pycache__/settings.cpython-310.pyc and b/Dhackathon/hackathon/__pycache__/settings.cpython-310.pyc differ diff --git a/Dhackathon/hackathon/__pycache__/urls.cpython-310.pyc b/Dhackathon/hackathon/__pycache__/urls.cpython-310.pyc index 0abe7eb1..df63bdef 100644 Binary files a/Dhackathon/hackathon/__pycache__/urls.cpython-310.pyc and b/Dhackathon/hackathon/__pycache__/urls.cpython-310.pyc differ diff --git a/Dhackathon/hackathon/settings.py b/Dhackathon/hackathon/settings.py index 9c5e1e82..5e17a8be 100644 --- a/Dhackathon/hackathon/settings.py +++ b/Dhackathon/hackathon/settings.py @@ -12,7 +12,7 @@ from pathlib import Path -# AUTH_USER_MODEL = 'nny.User' +AUTH_USER_MODEL = 'nny.User' # Build paths inside the project like this: BASE_DIR / 'subdir'. BASE_DIR = Path(__file__).resolve().parent.parent diff --git a/Dhackathon/hackathon/urls.py b/Dhackathon/hackathon/urls.py index a6b3e502..4b70796b 100644 --- a/Dhackathon/hackathon/urls.py +++ b/Dhackathon/hackathon/urls.py @@ -14,8 +14,9 @@ 2. Add a URL to urlpatterns: path('blog/', include('blog.urls')) """ from django.contrib import admin -from django.urls import path +from django.urls import path, include urlpatterns = [ path('admin/', admin.site.urls), + path('nny/', include('nny.urls')), ] diff --git a/Dhackathon/nny/__pycache__/__init__.cpython-310.pyc b/Dhackathon/nny/__pycache__/__init__.cpython-310.pyc new file mode 100644 index 00000000..14e11842 Binary files /dev/null and b/Dhackathon/nny/__pycache__/__init__.cpython-310.pyc differ diff --git a/Dhackathon/nny/__pycache__/admin.cpython-310.pyc b/Dhackathon/nny/__pycache__/admin.cpython-310.pyc new file mode 100644 index 00000000..f1a02890 Binary files /dev/null and b/Dhackathon/nny/__pycache__/admin.cpython-310.pyc differ diff --git a/Dhackathon/nny/__pycache__/apps.cpython-310.pyc b/Dhackathon/nny/__pycache__/apps.cpython-310.pyc new file mode 100644 index 00000000..1af8f13a Binary files /dev/null and b/Dhackathon/nny/__pycache__/apps.cpython-310.pyc differ diff --git a/Dhackathon/nny/__pycache__/models.cpython-310.pyc b/Dhackathon/nny/__pycache__/models.cpython-310.pyc new file mode 100644 index 00000000..fe8872d1 Binary files /dev/null and b/Dhackathon/nny/__pycache__/models.cpython-310.pyc differ diff --git a/Dhackathon/nny/__pycache__/serializers.cpython-310.pyc b/Dhackathon/nny/__pycache__/serializers.cpython-310.pyc new file mode 100644 index 00000000..a033a748 Binary files /dev/null and b/Dhackathon/nny/__pycache__/serializers.cpython-310.pyc differ diff --git a/Dhackathon/nny/__pycache__/urls.cpython-310.pyc b/Dhackathon/nny/__pycache__/urls.cpython-310.pyc new file mode 100644 index 00000000..56d1c9d4 Binary files /dev/null and b/Dhackathon/nny/__pycache__/urls.cpython-310.pyc differ diff --git a/Dhackathon/nny/__pycache__/views.cpython-310.pyc b/Dhackathon/nny/__pycache__/views.cpython-310.pyc new file mode 100644 index 00000000..4f9a49b7 Binary files /dev/null and b/Dhackathon/nny/__pycache__/views.cpython-310.pyc differ diff --git a/Dhackathon/nny/admin.py b/Dhackathon/nny/admin.py index 8c38f3f3..b6f637e8 100644 --- a/Dhackathon/nny/admin.py +++ b/Dhackathon/nny/admin.py @@ -1,3 +1,15 @@ from django.contrib import admin +from .models import User, Train, Seat # Register your models here. + +admin.site.register(User) +admin.site.register(Train) + +@admin.register(Seat) +class MyAdmin(admin.ModelAdmin): + list_display = ['id', 'train', 'seat_num', 'is_seated', 'station'] + list_display_links = ['id', 'train', 'seat_num', 'is_seated', 'station'] + + def short_content(self, seat): + return seat.content[:10] \ No newline at end of file diff --git a/Dhackathon/nny/migrations/0001_initial.py b/Dhackathon/nny/migrations/0001_initial.py new file mode 100644 index 00000000..e96bfc60 --- /dev/null +++ b/Dhackathon/nny/migrations/0001_initial.py @@ -0,0 +1,64 @@ +# Generated by Django 4.1 on 2022-08-07 03:35 + +from django.conf import settings +import django.contrib.auth.models +import django.contrib.auth.validators +from django.db import migrations, models +import django.db.models.deletion +import django.utils.timezone + + +class Migration(migrations.Migration): + + initial = True + + dependencies = [ + ('auth', '0012_alter_user_first_name_max_length'), + ] + + operations = [ + migrations.CreateModel( + name='User', + fields=[ + ('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), + ('password', models.CharField(max_length=128, verbose_name='password')), + ('last_login', models.DateTimeField(blank=True, null=True, verbose_name='last login')), + ('is_superuser', models.BooleanField(default=False, help_text='Designates that this user has all permissions without explicitly assigning them.', verbose_name='superuser status')), + ('username', models.CharField(error_messages={'unique': 'A user with that username already exists.'}, help_text='Required. 150 characters or fewer. Letters, digits and @/./+/-/_ only.', max_length=150, unique=True, validators=[django.contrib.auth.validators.UnicodeUsernameValidator()], verbose_name='username')), + ('first_name', models.CharField(blank=True, max_length=150, verbose_name='first name')), + ('last_name', models.CharField(blank=True, max_length=150, verbose_name='last name')), + ('is_staff', models.BooleanField(default=False, help_text='Designates whether the user can log into this admin site.', verbose_name='staff status')), + ('is_active', models.BooleanField(default=True, help_text='Designates whether this user should be treated as active. Unselect this instead of deleting accounts.', verbose_name='active')), + ('date_joined', models.DateTimeField(default=django.utils.timezone.now, verbose_name='date joined')), + ('email', models.EmailField(max_length=100, unique=True)), + ('groups', models.ManyToManyField(blank=True, help_text='The groups this user belongs to. A user will get all permissions granted to each of their groups.', related_name='user_set', related_query_name='user', to='auth.group', verbose_name='groups')), + ('user_permissions', models.ManyToManyField(blank=True, help_text='Specific permissions for this user.', related_name='user_set', related_query_name='user', to='auth.permission', verbose_name='user permissions')), + ], + options={ + 'verbose_name': 'user', + 'verbose_name_plural': 'users', + 'abstract': False, + }, + managers=[ + ('objects', django.contrib.auth.models.UserManager()), + ], + ), + migrations.CreateModel( + name='Train', + fields=[ + ('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), + ('train_id', models.IntegerField()), + ], + ), + migrations.CreateModel( + name='Seat', + fields=[ + ('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), + ('seat_num', models.IntegerField()), + ('is_seated', models.BooleanField(default=False)), + ('station', models.IntegerField()), + ('train', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='seat', to='nny.train')), + ('user', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to=settings.AUTH_USER_MODEL)), + ], + ), + ] diff --git a/Dhackathon/nny/migrations/0002_alter_seat_seat_num_alter_seat_station.py b/Dhackathon/nny/migrations/0002_alter_seat_seat_num_alter_seat_station.py new file mode 100644 index 00000000..7d38eb37 --- /dev/null +++ b/Dhackathon/nny/migrations/0002_alter_seat_seat_num_alter_seat_station.py @@ -0,0 +1,24 @@ +# Generated by Django 4.1 on 2022-08-09 12:53 + +import django.core.validators +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('nny', '0001_initial'), + ] + + operations = [ + migrations.AlterField( + model_name='seat', + name='seat_num', + field=models.IntegerField(validators=[django.core.validators.MinValueValidator(1), django.core.validators.MaxValueValidator(36)]), + ), + migrations.AlterField( + model_name='seat', + name='station', + field=models.IntegerField(blank=True, null=True, validators=[django.core.validators.MinValueValidator(1), django.core.validators.MaxValueValidator(63)]), + ), + ] diff --git a/Dhackathon/nny/migrations/__pycache__/0001_initial.cpython-310.pyc b/Dhackathon/nny/migrations/__pycache__/0001_initial.cpython-310.pyc new file mode 100644 index 00000000..4ad15faa Binary files /dev/null and b/Dhackathon/nny/migrations/__pycache__/0001_initial.cpython-310.pyc differ diff --git a/Dhackathon/nny/migrations/__pycache__/0002_alter_seat_seat_num_alter_seat_station.cpython-310.pyc b/Dhackathon/nny/migrations/__pycache__/0002_alter_seat_seat_num_alter_seat_station.cpython-310.pyc new file mode 100644 index 00000000..484eb4e2 Binary files /dev/null and b/Dhackathon/nny/migrations/__pycache__/0002_alter_seat_seat_num_alter_seat_station.cpython-310.pyc differ diff --git a/Dhackathon/nny/migrations/__pycache__/__init__.cpython-310.pyc b/Dhackathon/nny/migrations/__pycache__/__init__.cpython-310.pyc new file mode 100644 index 00000000..3b4fea2d Binary files /dev/null and b/Dhackathon/nny/migrations/__pycache__/__init__.cpython-310.pyc differ diff --git a/Dhackathon/nny/models.py b/Dhackathon/nny/models.py index 71a83623..cab97673 100644 --- a/Dhackathon/nny/models.py +++ b/Dhackathon/nny/models.py @@ -1,3 +1,18 @@ from django.db import models +from django.contrib.auth.models import AbstractUser +from django.core.validators import MinValueValidator, MaxValueValidator # Create your models here. + +class User(AbstractUser): + email = models.EmailField(max_length=100, unique=True) + +class Train(models.Model): + train_id = models.IntegerField() + +class Seat(models.Model): + train = models.ForeignKey(Train, on_delete=models.CASCADE, related_name='seat') + user = models.ForeignKey(User, on_delete=models.CASCADE) + seat_num = models.IntegerField(validators=[MinValueValidator(1), MaxValueValidator(36)]) + is_seated = models.BooleanField(default=False) + station = models.IntegerField(null=True, blank=True, validators=[MinValueValidator(1), MaxValueValidator(63)]) \ No newline at end of file diff --git a/Dhackathon/nny/serializers.py b/Dhackathon/nny/serializers.py new file mode 100644 index 00000000..ee28de61 --- /dev/null +++ b/Dhackathon/nny/serializers.py @@ -0,0 +1,14 @@ +from rest_framework import serializers +from .models import * + +class SeatSerializer(serializers.ModelSerializer): + class Meta: + model = Seat + fields = ['id', 'user', 'train', 'seat_num', 'is_seated', 'station'] + +class TrainSerializer(serializers.ModelSerializer): + seat = SeatSerializer(many=True, read_only=True) + + class Meta: + model = Train + fields = ['id', 'train_id', 'seat'] \ No newline at end of file diff --git a/Dhackathon/nny/urls.py b/Dhackathon/nny/urls.py new file mode 100644 index 00000000..50ed610a --- /dev/null +++ b/Dhackathon/nny/urls.py @@ -0,0 +1,10 @@ +from django.urls import path +from .views import * + +app_name = 'nny' + +urlpatterns = [ + path('trains/', TrainListView.as_view()), + path('trains/', TrainDetailView.as_view()), + path('seats/', SeatView.as_view()), +] \ No newline at end of file diff --git a/Dhackathon/nny/views.py b/Dhackathon/nny/views.py index 91ea44a2..de95e7a1 100644 --- a/Dhackathon/nny/views.py +++ b/Dhackathon/nny/views.py @@ -1,3 +1,32 @@ -from django.shortcuts import render +from django.shortcuts import get_object_or_404 +from .serializers import * +from .models import * +from rest_framework import views +from rest_framework.response import Response # Create your views here. + +class TrainListView(views.APIView): + def get(self, request, format=None): + trains=Train.objects.all() + serializer=TrainSerializer(trains, many=True) + return Response(serializer.data) + +class TrainDetailView(views.APIView): + def get(self, request, pk, format=None): + train = get_object_or_404(Train, pk=pk) + serializer = TrainSerializer(train) + return Response(serializer.data) + +class SeatView(views.APIView): + def patch(self, request, format=None): + serializer = SeatSerializer(data=request.data) + if serializer.is_valid(): + serializer.save() + return Response(serializer.data) + return Response(serializer.errors) + + def get(self, request, format=None): + seats=Seat.objects.all() + serializer=SeatSerializer(seats, many=True) + return Response(serializer.data) \ No newline at end of file