Skip to content

Commit

Permalink
Feat : Added Event Model (#102)
Browse files Browse the repository at this point in the history
Signed-off-by: Priyansh61 <[email protected]>
  • Loading branch information
Priyansh61 authored Nov 16, 2023
1 parent ab0c789 commit 3e62285
Show file tree
Hide file tree
Showing 11 changed files with 95 additions and 1 deletion.
2 changes: 1 addition & 1 deletion backend/accounts/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ class Meta:
'date_joined': {'read_only': True},
'last_login': {'read_only': True},
}

def create(self, validated_data):
password = validated_data.pop('password', None)

Expand Down
1 change: 1 addition & 0 deletions backend/core/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
'core',
'accounts',
'products',
'events',
]

REST_FRAMEWORK = {
Expand Down
1 change: 1 addition & 0 deletions backend/core/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,5 @@
path('admin/', admin.site.urls),
path('api/token/', include('auth.urls')),
path('api/accounts/', include('accounts.urls')),
path('api/events/', include('events.urls')),
]+ static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)
Empty file added backend/events/__init__.py
Empty file.
11 changes: 11 additions & 0 deletions backend/events/admin.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
from django.contrib import admin
from .models import Event
# Register your models here.


class EventAdmin(admin.ModelAdmin) :
list_display = ('title', 'date', 'time', 'location', 'ticket_price', 'event_type')
search_fields = ('title', 'description', 'location', 'email')
list_filter = ('event_type', 'date', 'time')

admin.site.register(Event, EventAdmin)
6 changes: 6 additions & 0 deletions backend/events/apps.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
from django.apps import AppConfig


class EventsConfig(AppConfig):
default_auto_field = 'django.db.models.BigAutoField'
name = 'events'
41 changes: 41 additions & 0 deletions backend/events/models.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
from django.db import models

# Create your models here.

event_type_choices = [
('virtual','Virtual'),
('physical','Physical'),
]
class Event (models.Model) :
title = models.CharField(max_length=200)
organizer_id = models.OneToOneField(
'accounts.Account',
on_delete=models.CASCADE,
default=None,
null=True,
blank=True,
)
description = models.TextField(max_length=600,
blank=True)
email = models.EmailField(max_length=254,
blank=True)
phone = models.CharField(max_length=15, blank=True)
date = models.DateField(
blank = False,
null = False,
)
time = models.TimeField(
blank = False,
null = False,
)
event_type = models.CharField(max_length=100,
choices=event_type_choices)

location = models.CharField(max_length=200)
ticket_price = models.DecimalField(max_digits=10, decimal_places=2)
created_at = models.DateTimeField(auto_now_add=True)
updated_at = models.DateTimeField(auto_now=True)


def __str__(self):
return self.title
12 changes: 12 additions & 0 deletions backend/events/serializers.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
from rest_framework import serializers
from .models import Event

class EventSerializer(serializers.ModelSerializer) :
class Meta:
model = Event
fields = '__all__'
extra_kwargs = {
'created_at': {'read_only': True},
'updated_at': {'read_only': True},
}

3 changes: 3 additions & 0 deletions backend/events/tests.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
from django.test import TestCase

# Create your tests here.
10 changes: 10 additions & 0 deletions backend/events/urls.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
from django.urls import path, include
from .views import EventViewSet
from rest_framework.routers import DefaultRouter

router = DefaultRouter()
router.register('', EventViewSet, basename='event')

urlpatterns = [
path('', include(router.urls)),
]
9 changes: 9 additions & 0 deletions backend/events/views.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
from rest_framework import viewsets
from .models import Event
from .serializers import EventSerializer

# Create your views here.

class EventViewSet(viewsets.ModelViewSet):
queryset = Event.objects.all()
serializer_class = EventSerializer

0 comments on commit 3e62285

Please sign in to comment.