From af16314adaea1858b1a0def731dd5cbe12dbb9fe Mon Sep 17 00:00:00 2001 From: albertoleoncio Date: Sat, 11 Jan 2025 14:42:38 -0300 Subject: [PATCH] Init --- ...organization_email_organization_website.py | 23 +++++++++++++++++++ orgs/models.py | 8 +++++++ orgs/serializers.py | 12 ++++++++++ 3 files changed, 43 insertions(+) create mode 100644 orgs/migrations/0009_organization_email_organization_website.py diff --git a/orgs/migrations/0009_organization_email_organization_website.py b/orgs/migrations/0009_organization_email_organization_website.py new file mode 100644 index 0000000..2117677 --- /dev/null +++ b/orgs/migrations/0009_organization_email_organization_website.py @@ -0,0 +1,23 @@ +# Generated by Django 4.2.11 on 2025-01-11 17:38 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('orgs', '0008_organization_tag_diff'), + ] + + operations = [ + migrations.AddField( + model_name='organization', + name='email', + field=models.EmailField(blank=True, help_text='The email address of the organization.', max_length=254, null=True), + ), + migrations.AddField( + model_name='organization', + name='website', + field=models.URLField(blank=True, help_text='The URL of the organization website.', null=True), + ), + ] diff --git a/orgs/models.py b/orgs/models.py index 8cb79a8..423af5c 100644 --- a/orgs/models.py +++ b/orgs/models.py @@ -49,6 +49,14 @@ class Organization(models.Model): message='Invalid URL format. The format should be https://meta.wikimedia.org/wiki/PageName' )] ) + email = models.EmailField( + blank=True, null=True, + help_text='The email address of the organization.', + ) + website = models.URLField( + blank=True, null=True, + help_text='The URL of the organization website.', + ) mastodon = models.URLField( blank=True, null=True, help_text='The URL of the organization Mastodon account.', diff --git a/orgs/serializers.py b/orgs/serializers.py index 88c5344..b2b2aa2 100644 --- a/orgs/serializers.py +++ b/orgs/serializers.py @@ -4,11 +4,23 @@ class OrganizationSerializer(serializers.ModelSerializer): + projects = serializers.SerializerMethodField() + events = serializers.SerializerMethodField() + class Meta: model = Organization fields = '__all__' read_only_fields = ['creation_date'] + def get_projects(self, obj): + from projects.models import ProjectMember + return ProjectMember.objects.filter(organization=obj, projectmemberacceptance__accepted=True).values_list('project', flat=True) + + def get_events(self, obj): + from events.models import EventOrganizations + return EventOrganizations.objects.filter(organization=obj).values_list('event', flat=True) + + class OrganizationTypeSerializer(serializers.ModelSerializer): class Meta: