Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

second commit #1

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
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
Binary file modified Dhackathon/db.sqlite3
Binary file not shown.
Binary file modified Dhackathon/hackathon/__pycache__/settings.cpython-310.pyc
Binary file not shown.
Binary file modified Dhackathon/hackathon/__pycache__/urls.cpython-310.pyc
Binary file not shown.
2 changes: 1 addition & 1 deletion Dhackathon/hackathon/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 2 additions & 1 deletion Dhackathon/hackathon/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -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')),
]
Binary file added Dhackathon/nny/__pycache__/__init__.cpython-310.pyc
Binary file not shown.
Binary file added Dhackathon/nny/__pycache__/admin.cpython-310.pyc
Binary file not shown.
Binary file added Dhackathon/nny/__pycache__/apps.cpython-310.pyc
Binary file not shown.
Binary file added Dhackathon/nny/__pycache__/models.cpython-310.pyc
Binary file not shown.
Binary file added Dhackathon/nny/__pycache__/serializers.cpython-310.pyc
Binary file not shown.
Binary file added Dhackathon/nny/__pycache__/urls.cpython-310.pyc
Binary file not shown.
Binary file added Dhackathon/nny/__pycache__/views.cpython-310.pyc
Binary file not shown.
12 changes: 12 additions & 0 deletions Dhackathon/nny/admin.py
Original file line number Diff line number Diff line change
@@ -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]
64 changes: 64 additions & 0 deletions Dhackathon/nny/migrations/0001_initial.py
Original file line number Diff line number Diff line change
@@ -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)),
],
),
]
Original file line number Diff line number Diff line change
@@ -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)]),
),
]
Binary file not shown.
Binary file not shown.
Binary file not shown.
15 changes: 15 additions & 0 deletions Dhackathon/nny/models.py
Original file line number Diff line number Diff line change
@@ -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)])
14 changes: 14 additions & 0 deletions Dhackathon/nny/serializers.py
Original file line number Diff line number Diff line change
@@ -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']
10 changes: 10 additions & 0 deletions Dhackathon/nny/urls.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
from django.urls import path
from .views import *

app_name = 'nny'

urlpatterns = [
path('trains/', TrainListView.as_view()),
path('trains/<int:pk>', TrainDetailView.as_view()),
path('seats/', SeatView.as_view()),
]
31 changes: 30 additions & 1 deletion Dhackathon/nny/views.py
Original file line number Diff line number Diff line change
@@ -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)