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 : Added Ticket and Event_Form #103

Merged
merged 6 commits into from
Nov 18, 2023
Merged
Show file tree
Hide file tree
Changes from 5 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
1 change: 1 addition & 0 deletions backend/core/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
'accounts',
'products',
'events',
'tickets',
]

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 @@ -9,4 +9,5 @@
path('api/token/', include('auth.urls')),
path('api/accounts/', include('accounts.urls')),
path('api/events/', include('events.urls')),
path('api/tickets/', include('tickets.urls')),
]+ static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)
9 changes: 8 additions & 1 deletion backend/events/admin.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from django.contrib import admin
from .models import Event
from .models import Event, Event_Form
# Register your models here.


Expand All @@ -8,4 +8,11 @@ class EventAdmin(admin.ModelAdmin) :
search_fields = ('title', 'description', 'location', 'email')
list_filter = ('event_type', 'date', 'time')

class Event_FormAdmin(admin.ModelAdmin) :
list_display = ('event', 'form_fields')
search_fields = ('event', 'form_fields')
list_filter = ('event', 'form_fields')

admin.site.register(Event_Form, Event_FormAdmin)

admin.site.register(Event, EventAdmin)
18 changes: 16 additions & 2 deletions backend/events/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
]
class Event (models.Model) :
title = models.CharField(max_length=200)
organizer_id = models.OneToOneField(
organizer = models.OneToOneField(
'accounts.Account',
on_delete=models.CASCADE,
default=None,
Expand Down Expand Up @@ -38,4 +38,18 @@ class Event (models.Model) :


def __str__(self):
return self.title
return self.title

class Event_Form (models.Model) :
event = models.OneToOneField(
'events.Event',
on_delete=models.CASCADE,
default=None,
null=False,
blank=False,
related_name='event_form',
)
form_fields = models.JSONField(default=dict)

def __str__(self):
return self.event.title
24 changes: 22 additions & 2 deletions backend/events/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,29 @@
class EventSerializer(serializers.ModelSerializer) :
class Meta:
model = Event
fields = '__all__'
fields = [
'title',
'organizer',
'description',
'email',
'phone',
'date',
'time',
'event_type',
'location',
'ticket_price',
'created_at',
'updated_at'
]
extra_kwargs = {
'created_at': {'read_only': True},
'updated_at': {'read_only': True},
}


class EventFormSerializer(serializers.ModelSerializer) :
class Meta:
model = Event
fields = [
'event',
'form_fields'
]
6 changes: 5 additions & 1 deletion backend/events/views.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
from rest_framework import viewsets
from .models import Event
from .serializers import EventSerializer
from .serializers import EventSerializer, EventFormSerializer

# Create your views here.

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

class EventFormViewSet(viewsets.ModelViewSet):
queryset = Event.objects.all()
serializer_class = EventFormSerializer
Empty file added backend/tickets/__init__.py
Empty file.
11 changes: 11 additions & 0 deletions backend/tickets/admin.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
from django.contrib import admin
from .models import Ticket


# Register your models here.
class TicketAdmin(admin.ModelAdmin) :
list_display = ('event', 'buyer', 'purchase_date', 'status')
search_fields = ('event', 'buyer', 'purchase_date', 'status')
list_filter = ('event', 'buyer', 'purchase_date', 'status')

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


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

# Create your models here.

status_enums = [
('pending','Pending'),
('approved','Approved'),
('rejected','Rejected'),
('cancelled','Cancelled'),
]

class Ticket (models.Model) :
event = models.ForeignKey(
'events.Event',
on_delete=models.CASCADE,
default=None,
null=False,
blank=False,
)
buyer = models.ForeignKey(
'accounts.Account',
on_delete=models.CASCADE,
default=None,
null=False,
blank=False,
)
response = models.JSONField(default=dict)
purchase_date = models.DateTimeField(auto_now_add=True)
status = models.CharField(max_length=100,
choices=status_enums)

Class Meta:
unique_together = [['event', 'buyer']]



def __str__(self):
return f'{self.event.title} {self.buyer.first_name} {self.buyer.last_name}'
14 changes: 14 additions & 0 deletions backend/tickets/serializers.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
from rest_framework import serializers
from .models import Ticket

class TicketSerializer(serializers.ModelSerializer) :
class Meta:
model = Ticket
fields = [
'id',
'event',
'buyer',
'response',
'purchase_date',
'status',
]
3 changes: 3 additions & 0 deletions backend/tickets/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/tickets/urls.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
from django.urls import path,include
from rest_framework.routers import DefaultRouter
from .views import TicketViewSet

router = DefaultRouter()
router.register('', TicketViewSet, basename='ticket')

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

# Create your views here.

class TicketViewSet(viewsets.ModelViewSet):
queryset = Ticket.objects.all()
serializer_class = TicketSerializer
Loading