diff --git a/pyproject.toml b/pyproject.toml index 3de6f57..6b3db5a 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -30,7 +30,8 @@ dependencies = [ "sphinx-rtd-theme", "gunicorn", "fontawesomefree", - "whitenoise" + "whitenoise", + "model_bakery" ] dynamic = ["version", "readme"] diff --git a/src/fellchensammlung/admin.py b/src/fellchensammlung/admin.py index 8c38f3f..0ab3679 100644 --- a/src/fellchensammlung/admin.py +++ b/src/fellchensammlung/admin.py @@ -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) \ No newline at end of file diff --git a/src/fellchensammlung/migrations/0001_initial.py b/src/fellchensammlung/migrations/0001_initial.py new file mode 100644 index 0000000..06e4a03 --- /dev/null +++ b/src/fellchensammlung/migrations/0001_initial.py @@ -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')), + ], + ), + ] diff --git a/src/fellchensammlung/models.py b/src/fellchensammlung/models.py index 71a8362..f53c376 100644 --- a/src/fellchensammlung/models.py +++ b/src/fellchensammlung/models.py @@ -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. diff --git a/src/fellchensammlung/urls.py b/src/fellchensammlung/urls.py index a9d7f56..9b9930f 100644 --- a/src/fellchensammlung/urls.py +++ b/src/fellchensammlung/urls.py @@ -4,4 +4,8 @@ from . import views urlpatterns = [ path("", views.index, name="index"), + # ex: /animal/5/ + path("/", views.animal_detail, name="animal-detail"), + # ex: /adoption_notice/7/ + path("/", views.adoption_notice_detail, name="adoption-notice-detail"), ] \ No newline at end of file diff --git a/src/fellchensammlung/views.py b/src/fellchensammlung/views.py index f9c11b4..d178ea2 100644 --- a/src/fellchensammlung/views.py +++ b/src/fellchensammlung/views.py @@ -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) diff --git a/src/notfellchen/main.py b/src/notfellchen/main.py index 08bc2dd..bf19fef 100644 --- a/src/notfellchen/main.py +++ b/src/notfellchen/main.py @@ -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)