From f8f62c2d0c16f25c2b951109b07e2d34c52e76ff Mon Sep 17 00:00:00 2001 From: Andrew4Coding Date: Thu, 3 Oct 2024 17:33:37 +0700 Subject: [PATCH] feat: initialize models.py --- DATABASE.md | 0 main/migrations/0001_initial.py | 98 +++++++++++++++++++++++++++++++++ main/models.py | 79 +++++++++++++++++++++++++- 3 files changed, 176 insertions(+), 1 deletion(-) create mode 100644 DATABASE.md create mode 100644 main/migrations/0001_initial.py diff --git a/DATABASE.md b/DATABASE.md new file mode 100644 index 0000000..e69de29 diff --git a/main/migrations/0001_initial.py b/main/migrations/0001_initial.py new file mode 100644 index 0000000..a55c414 --- /dev/null +++ b/main/migrations/0001_initial.py @@ -0,0 +1,98 @@ +# Generated by Django 5.1.1 on 2024-10-03 10:26 + +import django.db.models.deletion +from django.conf import settings +from django.db import migrations, models + + +class Migration(migrations.Migration): + + initial = True + + dependencies = [ + migrations.swappable_dependency(settings.AUTH_USER_MODEL), + ] + + operations = [ + migrations.CreateModel( + name='Merchandise', + fields=[ + ('merchId', models.AutoField(primary_key=True, serialize=False)), + ('name', models.CharField(max_length=200)), + ('description', models.TextField()), + ('price', models.DecimalField(decimal_places=2, max_digits=10)), + ('stock', models.IntegerField()), + ('created_at', models.DateTimeField(auto_now_add=True)), + ('updated_at', models.DateTimeField(auto_now=True)), + ], + ), + migrations.CreateModel( + name='TicketPrice', + fields=[ + ('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), + ('name', models.CharField(max_length=200)), + ('price', models.DecimalField(decimal_places=2, max_digits=10)), + ], + ), + migrations.CreateModel( + name='Event', + fields=[ + ('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), + ('title', models.CharField(max_length=200)), + ('description', models.TextField()), + ('category', models.CharField(choices=[('OL', 'Olahraga'), ('SN', 'Seni'), ('MS', 'Musik'), ('CP', 'Cosplay'), ('LG', 'Lingkungan'), ('VL', 'Volunteer'), ('LN', 'Lainnya')], default='LN', max_length=2)), + ('start_time', models.DateTimeField()), + ('end_time', models.DateTimeField()), + ('location', models.CharField(max_length=200)), + ('created_at', models.DateTimeField(auto_now_add=True)), + ('updated_at', models.DateTimeField(auto_now=True)), + ('merch', models.ManyToManyField(blank=True, to='main.merchandise')), + ], + ), + migrations.CreateModel( + name='Post', + fields=[ + ('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), + ('title', models.CharField(max_length=200)), + ('content', models.TextField()), + ('created_at', models.DateTimeField(auto_now_add=True)), + ('updated_at', models.DateTimeField(auto_now=True)), + ('event', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='main.event')), + ('reply', models.ManyToManyField(blank=True, to='main.post')), + ('user', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to=settings.AUTH_USER_MODEL)), + ], + ), + migrations.CreateModel( + name='Rating', + fields=[ + ('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), + ('rating', models.IntegerField()), + ('review', models.TextField()), + ('created_at', models.DateTimeField(auto_now_add=True)), + ('updated_at', models.DateTimeField(auto_now=True)), + ('rated_event', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='main.event')), + ('user', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to=settings.AUTH_USER_MODEL)), + ], + ), + migrations.AddField( + model_name='event', + name='user_rating', + field=models.ManyToManyField(blank=True, to='main.rating'), + ), + migrations.AddField( + model_name='event', + name='ticketPrice', + field=models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='main.ticketprice'), + ), + migrations.CreateModel( + name='UserProfile', + fields=[ + ('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), + ('bio', models.TextField()), + ('email', models.EmailField(max_length=254)), + ('boughtMerch', models.ManyToManyField(blank=True, to='main.merchandise')), + ('registeredEvent', models.ManyToManyField(blank=True, to='main.event')), + ('user', models.OneToOneField(on_delete=django.db.models.deletion.CASCADE, to=settings.AUTH_USER_MODEL)), + ], + ), + ] diff --git a/main/models.py b/main/models.py index 71a8362..b904bbf 100644 --- a/main/models.py +++ b/main/models.py @@ -1,3 +1,80 @@ from django.db import models +from django.contrib.auth.models import User -# Create your models here. +class UserProfile(models.Model): + user = models.OneToOneField(User, on_delete=models.CASCADE) + bio = models.TextField() + email = models.EmailField() + + registeredEvent = models.ManyToManyField('Event', blank=True) + boughtMerch = models.ManyToManyField('Merchandise', blank=True) + + def __str__(self): + return self.user.username + +# Class for Event Category +class EventCategory(models.TextChoices): + OLAHRAGA='OL', 'Olahraga', + SENI='SN', 'Seni', + MUSIK='MS', 'Musik', + COSPLAY='CP', 'Cosplay', + LINGKUNGAN='LG', 'Lingkungan', + VOLUNTEER='VL', 'Volunteer', + LAINNYA='LN', 'Lainnya' + +class TicketPrice(models.Model): + name = models.CharField(max_length=200) + price = models.DecimalField(max_digits=10, decimal_places=2) + + def isFree(self): + return self.price == 0 + +class Rating(models.Model): + user = models.ForeignKey(User, on_delete=models.CASCADE) + rated_event = models.ForeignKey('Event', on_delete=models.CASCADE) + rating = models.IntegerField() + review = models.TextField() + created_at = models.DateTimeField(auto_now_add=True) + updated_at = models.DateTimeField(auto_now=True) + +class Event(models.Model): + title = models.CharField(max_length=200) + description = models.TextField() + category = models.CharField( + choices=EventCategory.choices, + default=EventCategory.LAINNYA, + max_length=2 + ) + + ticketPrice = models.ForeignKey(TicketPrice, on_delete=models.CASCADE) + + start_time = models.DateTimeField() + end_time = models.DateTimeField() + location = models.CharField(max_length=200) + created_at = models.DateTimeField(auto_now_add=True) + updated_at = models.DateTimeField(auto_now=True) + + merch = models.ManyToManyField('Merchandise', blank=True) + + user_rating = models.ManyToManyField(Rating, blank=True) + + +class Merchandise(models.Model): + merchId = models.AutoField(primary_key=True) + name = models.CharField(max_length=200) + description = models.TextField() + price = models.DecimalField(max_digits=10, decimal_places=2) + stock = models.IntegerField() + created_at = models.DateTimeField(auto_now_add=True) + updated_at = models.DateTimeField(auto_now=True) + +class Post (models.Model): + title = models.CharField(max_length=200) + content = models.TextField() + created_at = models.DateTimeField(auto_now_add=True) + updated_at = models.DateTimeField(auto_now=True) + + user = models.ForeignKey(User, on_delete=models.CASCADE) + event = models.ForeignKey('Event', on_delete=models.CASCADE) + + reply = models.ManyToManyField('Post', blank=True) \ No newline at end of file