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

feat(core): add student model #66

Merged
merged 1 commit into from
Aug 18, 2023
Merged
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
12 changes: 10 additions & 2 deletions api/serializers.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,15 @@
from rest_framework import serializers
from backend.models import Event
from backend.models import Event, Student

class EventSerializer(serializers.ModelSerializer):
class Meta:
model = Event
fields = ('id', 'title', 'content', 'student', 'mentor', 'start_date', 'end_date', 'status')
fields = ('id', 'title', 'content', 'student', 'mentor', 'start_date', 'end_date', 'status')

# the student class

class StudentSerializer(serializers.ModelSerializer):
class Meta:
model = Student
fields = ('id', 'first_name','last_name','email')

3 changes: 3 additions & 0 deletions backend/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,6 @@ class EventAdmin(admin.ModelAdmin):

admin.site.register(models.Category)
# Register your models here.

admin.site.register(models.Student)

29 changes: 29 additions & 0 deletions backend/migrations/0002_rootuser_student.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# Generated by Django 4.1.2 on 2023-08-15 23:18

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('backend', '0001_initial'),
]

operations = [
migrations.CreateModel(
name='Rootuser',
fields=[
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('name', models.CharField(max_length=100)),
],
),
migrations.CreateModel(
name='Student',
fields=[
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('first_name', models.CharField(max_length=100)),
('last_name', models.CharField(max_length=100)),
('email', models.EmailField(max_length=254, unique=True)),
],
),
]
16 changes: 15 additions & 1 deletion backend/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,26 @@
# name = models.CharField(max_length=100, blank=False, null=True)
# phone = models.CharField(max_length=20, blank=True, null=True)


class Rootuser(models.Model):
name = models.CharField(max_length=100)

class Category(models.Model):
name = models.CharField(max_length=100)

def __str__(self):
return self.name


class Student(models.Model):

first_name = models.CharField(max_length=100)
last_name = models.CharField(max_length=100)
email = models.EmailField(unique=True)


def __str__(self):
return f"{self.first_name} {self.last_name}"

# # create a model with two different user
# class Mentor(models.Model):
# user = models.OneToOneField(User, on_delete=models.CASCADE, primary_key=True, related_name='mentor')
Expand Down
8 changes: 5 additions & 3 deletions backend/tests/test_models.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from django.test import TestCase
from django.contrib.auth.models import User
from backend.models import Event, Category
from backend.models import Event, Category, Student
from django.utils import timezone


Expand Down Expand Up @@ -41,8 +41,10 @@ def test_event_content(self):
self.assertEqual(str(event), 'Event Title')
self.assertEqual(str(category), 'django')



def test_student(self):
test_user = Student.objects.create(first_name='Robera',last_name='Melaek',email='[email protected]')
username = Student.objects.get(id=1)
assert(username.first_name,'Robera')



Expand Down