2023-10-03 17:55:41 +02:00
|
|
|
from django.contrib.auth import get_user_model
|
|
|
|
from django.db import models
|
|
|
|
from django.forms import ModelForm
|
|
|
|
from django import forms
|
2023-11-06 16:21:10 +01:00
|
|
|
from captcha.fields import CaptchaField
|
2023-11-06 17:34:45 +01:00
|
|
|
from random import randrange
|
2023-10-03 17:55:41 +02:00
|
|
|
# Create your models here.
|
|
|
|
|
|
|
|
User = get_user_model()
|
|
|
|
|
|
|
|
class Author(models.Model):
|
|
|
|
user = models.OneToOneField(User, on_delete=models.CASCADE)
|
|
|
|
def __str__(self):
|
|
|
|
return self.user.username
|
|
|
|
|
|
|
|
class Category(models.Model):
|
|
|
|
title = models.CharField(max_length=20)
|
|
|
|
subtitle = models.CharField(max_length=20)
|
|
|
|
slug = models.SlugField()
|
|
|
|
def __str__(self):
|
|
|
|
return self.title
|
|
|
|
|
|
|
|
class Post(models.Model):
|
|
|
|
title = models.CharField(max_length=100)
|
|
|
|
author = models.ForeignKey(Author, on_delete=models.CASCADE)
|
2023-11-06 17:34:45 +01:00
|
|
|
slug = models.SlugField(blank=True, editable=False)
|
2023-11-06 17:27:22 +01:00
|
|
|
overview = models.TextField(blank=True, editable=False)
|
2023-10-03 17:55:41 +02:00
|
|
|
timestamp = models.DateTimeField(auto_now_add=True)
|
|
|
|
content = models.TextField()
|
|
|
|
categories = models.ManyToManyField(Category)
|
|
|
|
featured = models.BooleanField()
|
|
|
|
|
|
|
|
def __str__(self):
|
|
|
|
return self.title
|
|
|
|
|
2023-11-06 17:27:22 +01:00
|
|
|
def save(self, *args, **kwargs):
|
|
|
|
self.overview = self.content[:33] + "..."
|
2023-11-09 19:13:35 +01:00
|
|
|
if not self.slug: self.slug = self.title[:7].lower() + "-" + str(randrange(1000, 9999, 1))
|
2023-11-06 17:27:22 +01:00
|
|
|
super().save(*args, **kwargs)
|
|
|
|
|
2023-10-03 17:55:41 +02:00
|
|
|
class Contact(models.Model):
|
|
|
|
pseudonym = models.CharField(max_length=250)
|
|
|
|
mail = models.EmailField(blank=True)
|
|
|
|
betreff = models.CharField(max_length=500)
|
|
|
|
nachricht = models.CharField(max_length=10000)
|
|
|
|
timestamp = models.DateTimeField(auto_now_add=True)
|
|
|
|
|
|
|
|
def __str__(self):
|
|
|
|
return self.pseudonym
|
|
|
|
|
2023-10-04 21:35:26 +02:00
|
|
|
class ContactForm(forms.ModelForm):
|
2023-11-06 16:21:10 +01:00
|
|
|
captcha = CaptchaField()
|
2023-10-03 17:55:41 +02:00
|
|
|
class Meta:
|
|
|
|
model = Contact
|
2023-11-06 16:21:10 +01:00
|
|
|
fields = ["pseudonym", "mail", "betreff", "nachricht", "captcha"]
|
2023-10-04 19:21:30 +02:00
|
|
|
|
|
|
|
GESCHLECHTER = [("Männlich", "Männlich"), ("Weiblich","Weiblich"),("Andere","Andere")]
|
|
|
|
ERNÄHRUNG = [("Vegetarisch","Vegetarisch"),("Vegan","Vegan"),("Glutenfrei","Glutenfrei")]
|
|
|
|
class Registrant(models.Model):
|
2023-10-28 13:14:13 +02:00
|
|
|
name = models.CharField(max_length=64,blank=True)
|
|
|
|
mail = models.CharField(max_length=77,blank=True)
|
|
|
|
phone = models.CharField(max_length=33,blank=True)
|
2023-10-04 19:21:30 +02:00
|
|
|
rate_reduced = models.BooleanField()
|
2023-10-28 13:14:13 +02:00
|
|
|
address_street = models.CharField(max_length=256,blank=True)
|
|
|
|
address_plz = models.CharField(max_length=12,blank=True)
|
|
|
|
address_town = models.CharField(max_length=33,blank=True)
|
|
|
|
birthdate = models.CharField(max_length=33,blank=True)
|
|
|
|
gender = models.CharField(max_length=33, blank=True, choices=GESCHLECHTER)
|
|
|
|
food = models.CharField(max_length=33, blank=True, choices=ERNÄHRUNG)
|
|
|
|
music = models.CharField(max_length=128,blank=True)
|
2023-10-04 19:21:30 +02:00
|
|
|
cake = models.BooleanField()
|
|
|
|
publish_address = models.BooleanField()
|
|
|
|
publish_phone = models.BooleanField()
|
2023-10-28 13:14:13 +02:00
|
|
|
info = models.CharField(max_length=777,blank=True)
|
2023-11-03 19:36:44 +01:00
|
|
|
message = models.CharField(max_length=2100,blank=True)
|
2023-10-04 19:21:30 +02:00
|
|
|
|
|
|
|
timestamp = models.DateTimeField(auto_now_add=True)
|
2023-10-28 13:14:13 +02:00
|
|
|
payed = models.BooleanField(default=False)
|
2024-02-09 23:12:20 +01:00
|
|
|
canceled = models.BooleanField(default=False)
|
|
|
|
team = models.BooleanField(default=False)
|
2023-10-04 21:35:26 +02:00
|
|
|
|
2023-11-16 12:57:19 +01:00
|
|
|
def __str__(self):
|
|
|
|
return self.name
|
|
|
|
|
2023-10-04 21:35:26 +02:00
|
|
|
class RegisterForm(ModelForm):
|
2023-11-06 16:21:10 +01:00
|
|
|
captcha = CaptchaField()
|
2023-10-04 21:35:26 +02:00
|
|
|
class Meta:
|
|
|
|
model = Registrant
|
2023-11-06 16:21:10 +01:00
|
|
|
fields = ["name","mail","phone","rate_reduced","address_street","address_plz","address_town","birthdate","gender","food","music","cake","publish_address","publish_phone","info","message", "captcha"]
|
2023-10-08 18:13:35 +02:00
|
|
|
gender = forms.ChoiceField(widget=forms.RadioSelect,choices=GESCHLECHTER)
|
|
|
|
food = forms.ChoiceField(widget=forms.RadioSelect,choices=ERNÄHRUNG)
|