-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
make a simple event management/registration system
- Loading branch information
Showing
17 changed files
with
406 additions
and
147 deletions.
There are no files selected for viewing
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
from django.contrib import admin | ||
from .models import EventRegistration, Event | ||
|
||
|
||
@admin.register(Event) | ||
class EventAdmin(admin.ModelAdmin): | ||
search_fields = ["name"] | ||
list_display = [ | ||
"name", | ||
"venue", | ||
"start_time", | ||
"accept_reg", | ||
"show_on_home", | ||
"event_page", | ||
] | ||
list_filter = ["show_on_home", "accept_reg"] | ||
fields = [ | ||
"name", | ||
"description", | ||
"cover_image", | ||
"venue", | ||
"start_time", | ||
"end_time", | ||
"accept_reg", | ||
"show_on_home", | ||
] | ||
|
||
|
||
@admin.register(EventRegistration) | ||
class EventRegistrationAdmin(admin.ModelAdmin): | ||
search_fields = ["event", "user"] | ||
list_display = ["user", "event"] | ||
list_filter = ["event__name"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
from django.apps import AppConfig | ||
|
||
|
||
class HapsConfig(AppConfig): | ||
default_auto_field = "django.db.models.BigAutoField" | ||
name = "haps" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
# Generated by Django 4.2.1 on 2023-12-23 19:40 | ||
|
||
from django.conf import settings | ||
from django.db import migrations, models | ||
import django.db.models.deletion | ||
import utils.images | ||
|
||
|
||
class Migration(migrations.Migration): | ||
initial = True | ||
|
||
dependencies = [ | ||
migrations.swappable_dependency(settings.AUTH_USER_MODEL), | ||
] | ||
|
||
operations = [ | ||
migrations.CreateModel( | ||
name="Event", | ||
fields=[ | ||
( | ||
"id", | ||
models.BigAutoField( | ||
auto_created=True, | ||
primary_key=True, | ||
serialize=False, | ||
verbose_name="ID", | ||
), | ||
), | ||
("name", models.CharField(max_length=256)), | ||
("slug", models.SlugField(unique=True)), | ||
("description", models.TextField(max_length=4096)), | ||
( | ||
"cover_image", | ||
models.ImageField( | ||
blank=True, null=True, upload_to=utils.images.upload_image_to | ||
), | ||
), | ||
("venue", models.CharField(max_length=128)), | ||
("start_time", models.DateField()), | ||
("end_time", models.DateField(blank=True, null=True)), | ||
( | ||
"accept_reg", | ||
models.BooleanField(verbose_name="Accepting registrations ?"), | ||
), | ||
( | ||
"show_on_home", | ||
models.BooleanField(verbose_name="Show on Home Page ?"), | ||
), | ||
], | ||
), | ||
migrations.CreateModel( | ||
name="EventRegistration", | ||
fields=[ | ||
( | ||
"id", | ||
models.BigAutoField( | ||
auto_created=True, | ||
primary_key=True, | ||
serialize=False, | ||
verbose_name="ID", | ||
), | ||
), | ||
( | ||
"event", | ||
models.ForeignKey( | ||
on_delete=django.db.models.deletion.CASCADE, to="haps.event" | ||
), | ||
), | ||
( | ||
"user", | ||
models.ForeignKey( | ||
on_delete=django.db.models.deletion.CASCADE, | ||
to=settings.AUTH_USER_MODEL, | ||
), | ||
), | ||
], | ||
), | ||
] |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
from django.db import models | ||
from django.contrib.auth import get_user_model | ||
from django.utils.html import format_html | ||
from utils.images import upload_image_to | ||
from utils.slugs import generate_unique_slug | ||
|
||
User = get_user_model() | ||
|
||
|
||
class Event(models.Model): | ||
name = models.CharField(max_length=256) | ||
slug = models.SlugField(unique=True, blank=True) | ||
description = models.TextField(max_length=4096) | ||
cover_image = models.ImageField(upload_to=upload_image_to, blank=True, null=True) | ||
venue = models.CharField(max_length=128) | ||
start_time = models.DateField() | ||
end_time = models.DateField(null=True, blank=True) | ||
accept_reg = models.BooleanField(verbose_name="Accepting registrations ?") | ||
show_on_home = models.BooleanField(verbose_name="Show on Home Page ?") | ||
|
||
def __str__(self): | ||
return self.name + str(self.start_time) | ||
|
||
def save(self, *args, **kwargs): | ||
if self.slug == "": | ||
self.slug = generate_unique_slug(self.name, Event) | ||
super().save(args, kwargs) | ||
|
||
def get_absolute_url(self): | ||
return f"/events/e/{self.slug}" | ||
|
||
def event_page(self): | ||
return format_html(f'<a href="{self.get_absolute_url()}" target="_blank">View Page</a>') | ||
|
||
|
||
class EventRegistration(models.Model): | ||
event = models.ForeignKey(Event, on_delete=models.CASCADE) | ||
user = models.ForeignKey(User, on_delete=models.CASCADE) | ||
|
||
def __str__(self) -> str: | ||
return self.user.__str__() + "%" + self.event.__str__() |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
{% extends "commons.html" %} | ||
{% block title %} Events {% endblock title %} | ||
{%block content %} | ||
|
||
|
||
<div class="flex justify-center flex-wrap"> | ||
|
||
{%for hap in haps %} | ||
|
||
<div | ||
class="max-w-sm bg-white border border-gray-200 rounded-lg shadow dark:bg-gray-800 dark:border-gray-700 mb-4 mt-4 ml-4 mr-4" | ||
> | ||
<a href="#"> | ||
<img class="rounded-t-lg" src="{{hap.cover_image.url}}" alt="" /> | ||
</a> | ||
<div class="p-5"> | ||
<a href="#"> | ||
<h5 | ||
class="mb-2 text-2xl font-bold tracking-tight text-gray-900 dark:text-white" | ||
> | ||
{{hap.name}} | ||
</h5> | ||
</a> | ||
<p class="mb-3 font-normal text-gray-700 dark:text-gray-400"> | ||
{{hap.description}} | ||
</p> | ||
|
||
|
||
<p> <i class="fa-solid fa-location-dot"></i> {{hap.venue}} | ||
|
||
</p> | ||
<p> <i class="fa-solid fa-calendar"></i> {{hap.start_time}}</p> | ||
<a | ||
href="{{hap.get_absolute_url}}" | ||
class="inline-flex items-center px-3 py-2 text-sm font-medium text-center text-white bg-primary-700 rounded-lg hover:bg-primary-800 focus:ring-4 focus:outline-none focus:ring-primary-300 dark:bg-primary-600 dark:hover:bg-primary-700 dark:focus:ring-primary-800 mt-4" | ||
> | ||
Read more | ||
<svg | ||
class="rtl:rotate-180 w-3.5 h-3.5 ms-2" | ||
aria-hidden="true" | ||
xmlns="http://www.w3.org/2000/svg" | ||
fill="none" | ||
viewBox="0 0 14 10" | ||
> | ||
<path | ||
stroke="currentColor" | ||
stroke-linecap="round" | ||
stroke-linejoin="round" | ||
stroke-width="2" | ||
d="M1 5h12m0 0L9 1m4 4L9 9" | ||
/> | ||
</svg> | ||
</a> | ||
</div> | ||
</div> | ||
|
||
|
||
{% endfor %} | ||
|
||
|
||
|
||
</div> | ||
{% endblock %} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
from django.test import TestCase | ||
|
||
# Create your tests here. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
from django.urls import path | ||
|
||
from . import views | ||
|
||
app_name = "haps" | ||
|
||
urlpatterns = [ | ||
path("", views.haps_list, name="events"), | ||
path("e/<slug>", views.haps_item, name="event_item"), | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
from django.shortcuts import render | ||
from django.http import HttpRequest, Http404 | ||
from .models import Event | ||
import logging | ||
|
||
log = logging.getLogger(__name__) | ||
|
||
|
||
def haps_list(request: HttpRequest): | ||
haps = Event.objects.all() | ||
context = {"haps": haps} | ||
return render(request, "haps/list.html", context=context) | ||
|
||
|
||
def haps_item(request: HttpRequest, slug: str): | ||
event = Event.objects.get(slug=slug) | ||
context = {"event": event} | ||
|
||
return render(request, "haps/item.html", context=context) |
Oops, something went wrong.