feat: Add general model

This commit is contained in:
moanos [he/him] 2024-03-18 08:26:21 +01:00
parent 3de4935435
commit 3d7c1f3280
7 changed files with 173 additions and 3 deletions

View File

@ -30,7 +30,8 @@ dependencies = [
"sphinx-rtd-theme",
"gunicorn",
"fontawesomefree",
"whitenoise"
"whitenoise",
"model_bakery"
]
dynamic = ["version", "readme"]

View File

@ -1,3 +1,11 @@
from django.contrib import admin
# Register your models here.
from django.contrib import admin
from .models import Animal, Species, RescueOrganization, AdoptionNotice, Location
admin.site.register(Animal)
admin.site.register(Species)
admin.site.register(RescueOrganization)
admin.site.register(Location)
admin.site.register(AdoptionNotice)

View File

@ -0,0 +1,73 @@
# Generated by Django 5.0.3 on 2024-03-17 22:05
import django.db.models.deletion
from django.db import migrations, models
class Migration(migrations.Migration):
initial = True
dependencies = [
]
operations = [
migrations.CreateModel(
name='Location',
fields=[
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('name', models.CharField(max_length=200)),
('postcode', models.CharField(max_length=200)),
('country', models.CharField(choices=[('DE', 'Germany'), ('AT', 'Austria'), ('CH', 'Switzerland')], max_length=20)),
('description', models.TextField(blank=True, null=True, verbose_name='Description')),
],
),
migrations.CreateModel(
name='Species',
fields=[
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('name', models.CharField(help_text='Enter a animal species', max_length=200, verbose_name='Name')),
],
options={
'verbose_name': 'Species',
'verbose_name_plural': 'Species',
},
),
migrations.CreateModel(
name='RescueOrganization',
fields=[
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('name', models.CharField(max_length=200)),
('trusted', models.BooleanField(default=False, verbose_name='Trusted')),
('instagram', models.URLField(blank=True, null=True, verbose_name='Instagram profile')),
('facebook', models.URLField(blank=True, null=True, verbose_name='Facebook profile')),
('fediverse_profile', models.URLField(blank=True, null=True, verbose_name='Fediverse profile')),
('website', models.URLField(blank=True, null=True, verbose_name='Website')),
('location', models.ForeignKey(on_delete=django.db.models.deletion.PROTECT, to='fellchensammlung.location')),
],
),
migrations.CreateModel(
name='AdoptionNotice',
fields=[
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('created_at', models.DateField(verbose_name='Created at')),
('searching_since', models.DateField(verbose_name='Searching for a home since')),
('name', models.CharField(max_length=200)),
('description', models.TextField(blank=True, null=True, verbose_name='Description')),
('further_information', models.URLField(blank=True, null=True, verbose_name='Link to further information')),
('group_only', models.BooleanField(default=False, verbose_name='Only group adoption')),
('organization', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, to='fellchensammlung.rescueorganization', verbose_name='Organization')),
],
),
migrations.CreateModel(
name='Animal',
fields=[
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('date_of_birth', models.DateField(blank=True, null=True, verbose_name='Date of birth')),
('name', models.CharField(max_length=200)),
('description', models.TextField(blank=True, null=True, verbose_name='Description')),
('adoption_notice', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='fellchensammlung.adoptionnotice')),
('species', models.ForeignKey(on_delete=django.db.models.deletion.PROTECT, to='fellchensammlung.species')),
],
),
]

View File

@ -1,3 +1,74 @@
from django.db import models
from django.utils.translation import gettext_lazy as _
class Species(models.Model):
"""Model representing a species of animal."""
name = models.CharField(max_length=200, help_text=_('Enter a animal species'),
verbose_name=_('Name'))
def __str__(self):
"""String for representing the Model object."""
return self.name
class Meta:
verbose_name = _('Species')
verbose_name_plural = _('Species')
class Location(models.Model):
def __str__(self):
return f"{self.name}"
GERMANY = "DE"
AUSTRIA = "AT"
SWITZERLAND = "CH"
COUNTRIES_CHOICES = {
GERMANY: "Germany",
AUSTRIA: "Austria",
SWITZERLAND: "Switzerland"
}
name = models.CharField(max_length=200)
postcode = models.CharField(max_length=200)
country = models.CharField(max_length=20, choices=COUNTRIES_CHOICES)
description = models.TextField(null=True, blank=True, verbose_name=_('Description'))
class RescueOrganization(models.Model):
def __str__(self):
return f"{self.name}"
name = models.CharField(max_length=200)
trusted = models.BooleanField(default=False, verbose_name=_('Trusted'))
location = models.ForeignKey(Location, on_delete=models.PROTECT)
instagram = models.URLField(null=True, blank=True, verbose_name=_('Instagram profile'))
facebook = models.URLField(null=True, blank=True, verbose_name=_('Facebook profile'))
fediverse_profile = models.URLField(null=True, blank=True, verbose_name=_('Fediverse profile'))
website = models.URLField(null=True, blank=True, verbose_name=_('Website'))
class Animal(models.Model):
def __str__(self):
return f"{self.name}"
date_of_birth = models.DateField(null=True, blank=True, verbose_name=_('Date of birth'))
name = models.CharField(max_length=200)
description = models.TextField(null=True, blank=True, verbose_name=_('Description'))
species = models.ForeignKey(Species, on_delete=models.PROTECT)
class AdoptionNotice(models.Model):
def __str__(self):
return f"{self.name}"
created_at = models.DateField(verbose_name=_('Created at'))
searching_since = models.DateField(verbose_name=_('Searching for a home since'))
name = models.CharField(max_length=200)
description = models.TextField(null=True, blank=True, verbose_name=_('Description'))
organization = models.ForeignKey(RescueOrganization, blank=True, null=True, on_delete=models.SET_NULL,
verbose_name=_('Organization'))
further_information = models.URLField(null=True, blank=True, verbose_name=_('Link to further information'))
group_only = models.BooleanField(default=False, verbose_name=_('Only group adoption'))
animals = models.ManyToManyField(Animal)
# Create your models here.

View File

@ -4,4 +4,8 @@ from . import views
urlpatterns = [
path("", views.index, name="index"),
# ex: /animal/5/
path("<int:animal_id>/", views.animal_detail, name="animal-detail"),
# ex: /adoption_notice/7/
path("<int:adoption_notice_id>/", views.adoption_notice_detail, name="adoption-notice-detail"),
]

View File

@ -5,3 +5,12 @@ from django.http import HttpResponse
def index(request):
return HttpResponse("Hello, world. Look at all the little guys&girls and non-binary pals!")
def adoption_notice_detail(request, adoption_notice_id):
return HttpResponse("You're looking at adoption notice %s." % adoption_notice_id)
def animal_detail(request, animal_id):
response = "You're looking at animal %s."
return HttpResponse(response % animal_id)

View File

@ -18,6 +18,10 @@ def main():
"forget to activate a virtual environment?"
) from exc
if sys.argv[1] == "populate":
from fellchensammlung.populate_with_testdata import populate_with_testdata
populate_with_testdata()
execute_from_command_line(sys.argv)