78 lines
2.7 KiB
Python
78 lines
2.7 KiB
Python
from django.contrib.auth import get_user_model
|
|
from django.db import models
|
|
from django.forms import ModelForm
|
|
from django import forms
|
|
# 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)
|
|
slug = models.SlugField()
|
|
overview = models.TextField()
|
|
timestamp = models.DateTimeField(auto_now_add=True)
|
|
content = models.TextField()
|
|
categories = models.ManyToManyField(Category)
|
|
featured = models.BooleanField()
|
|
|
|
def __str__(self):
|
|
return self.title
|
|
|
|
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
|
|
|
|
class ContactForm(forms.ModelForm):
|
|
class Meta:
|
|
model = Contact
|
|
fields = ["pseudonym", "mail", "betreff", "nachricht"]
|
|
|
|
GESCHLECHTER = [("Männlich", "Männlich"), ("Weiblich","Weiblich"),("Andere","Andere")]
|
|
ERNÄHRUNG = [("Vegetarisch","Vegetarisch"),("Vegan","Vegan"),("Glutenfrei","Glutenfrei")]
|
|
class Registrant(models.Model):
|
|
name = models.CharField(max_length=64)
|
|
mail = models.EmailField()
|
|
phone = models.CharField(max_length=21)
|
|
rate_reduced = models.BooleanField()
|
|
address = models.CharField(max_length=256)
|
|
birthdate = models.DateField()
|
|
gender = models.CharField(max_length=32, blank=False, choices=GESCHLECHTER)
|
|
food = models.CharField(max_length=32, blank=False, choices=ERNÄHRUNG)
|
|
music = models.CharField(max_length=128)
|
|
cake = models.BooleanField()
|
|
publish_address = models.BooleanField()
|
|
publish_phone = models.BooleanField()
|
|
info = models.CharField(max_length=777)
|
|
message = models.TextField(2100)
|
|
|
|
timestamp = models.DateTimeField(auto_now_add=True)
|
|
payed = models.BooleanField()
|
|
slug = models.SlugField()
|
|
|
|
|
|
class RegisterForm(ModelForm):
|
|
class Meta:
|
|
model = Registrant
|
|
fields = ["name","mail","phone","rate_reduced","address","birthdate","gender","food","music","cake","publish_address","publish_phone","info","message"]
|
|
gender = forms.ChoiceField(widget=forms.RadioSelect,choices=GESCHLECHTER)
|
|
food = forms.ChoiceField(widget=forms.RadioSelect,choices=ERNÄHRUNG)
|