diff --git a/config/__pycache__/settings.cpython-311.pyc b/config/__pycache__/settings.cpython-311.pyc index 881731c..4495897 100644 Binary files a/config/__pycache__/settings.cpython-311.pyc and b/config/__pycache__/settings.cpython-311.pyc differ diff --git a/config/__pycache__/urls.cpython-311.pyc b/config/__pycache__/urls.cpython-311.pyc index 42d995d..3ad7955 100644 Binary files a/config/__pycache__/urls.cpython-311.pyc and b/config/__pycache__/urls.cpython-311.pyc differ diff --git a/config/settings.py b/config/settings.py index 291d043..5e7d49d 100644 --- a/config/settings.py +++ b/config/settings.py @@ -180,3 +180,7 @@ if EMAIL_USE_SSL: # https://docs.djangoproject.com/en/5.2/ref/settings/#default-auto-field DEFAULT_AUTO_FIELD = 'django.db.models.BigAutoField' + +MEDIA_URL = '/media/' +MEDIA_ROOT = BASE_DIR / 'media' + diff --git a/config/urls.py b/config/urls.py index bcfc074..069ee99 100644 --- a/config/urls.py +++ b/config/urls.py @@ -1,19 +1,3 @@ -""" -URL configuration for config project. - -The `urlpatterns` list routes URLs to views. For more information please see: - https://docs.djangoproject.com/en/5.2/topics/http/urls/ -Examples: -Function views - 1. Add an import: from my_app import views - 2. Add a URL to urlpatterns: path('', views.home, name='home') -Class-based views - 1. Add an import: from other_app.views import Home - 2. Add a URL to urlpatterns: path('', Home.as_view(), name='home') -Including another URLconf - 1. Import the include() function: from django.urls import include, path - 2. Add a URL to urlpatterns: path('blog/', include('blog.urls')) -""" from django.contrib import admin from django.urls import include, path from django.conf import settings @@ -27,3 +11,4 @@ urlpatterns = [ if settings.DEBUG: urlpatterns += static("/assets/", document_root=settings.BASE_DIR / "assets") urlpatterns += static(settings.STATIC_URL, document_root=settings.STATIC_ROOT) + urlpatterns += static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT) \ No newline at end of file diff --git a/core/__pycache__/models.cpython-311.pyc b/core/__pycache__/models.cpython-311.pyc index 18a063c..bd9adb9 100644 Binary files a/core/__pycache__/models.cpython-311.pyc and b/core/__pycache__/models.cpython-311.pyc differ diff --git a/core/__pycache__/urls.cpython-311.pyc b/core/__pycache__/urls.cpython-311.pyc index ebb8c6e..5ed621c 100644 Binary files a/core/__pycache__/urls.cpython-311.pyc and b/core/__pycache__/urls.cpython-311.pyc differ diff --git a/core/__pycache__/views.cpython-311.pyc b/core/__pycache__/views.cpython-311.pyc index 8d204fa..3e91e5a 100644 Binary files a/core/__pycache__/views.cpython-311.pyc and b/core/__pycache__/views.cpython-311.pyc differ diff --git a/core/migrations/0001_initial.py b/core/migrations/0001_initial.py new file mode 100644 index 0000000..794d8bc --- /dev/null +++ b/core/migrations/0001_initial.py @@ -0,0 +1,41 @@ +# Generated by Django 5.2.7 on 2026-02-28 04:39 + +import django.db.models.deletion +from django.conf import settings +from django.db import migrations, models + + +class Migration(migrations.Migration): + + initial = True + + dependencies = [ + migrations.swappable_dependency(settings.AUTH_USER_MODEL), + ] + + operations = [ + migrations.CreateModel( + name='Profile', + fields=[ + ('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), + ('course', models.CharField(blank=True, max_length=255)), + ('year', models.CharField(blank=True, choices=[('Year 1', 'Year 1'), ('Year 2', 'Year 2'), ('Year 3', 'Year 3'), ('Year 4+', 'Year 4+'), ('Postgraduate', 'Postgraduate')], max_length=50)), + ('location', models.CharField(blank=True, choices=[('Canley', 'Canley'), ('Leamington Spa', 'Leamington Spa'), ('On-Campus', 'On-Campus'), ('Coventry', 'Coventry'), ('Other', 'Other')], max_length=50)), + ('looking_for', models.CharField(blank=True, choices=[('Friends', 'Friends'), ('Short-term', 'Short-term'), ('Long-term', 'Long-term')], max_length=50)), + ('bio', models.TextField(blank=True, max_length=500)), + ('is_subscribed', models.BooleanField(default=False)), + ('last_online', models.DateTimeField(auto_now=True)), + ('user', models.OneToOneField(on_delete=django.db.models.deletion.CASCADE, related_name='profile', to=settings.AUTH_USER_MODEL)), + ], + ), + migrations.CreateModel( + name='Photo', + fields=[ + ('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), + ('image', models.ImageField(upload_to='profile_photos/')), + ('is_primary', models.BooleanField(default=False)), + ('uploaded_at', models.DateTimeField(auto_now_add=True)), + ('profile', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='photos', to='core.profile')), + ], + ), + ] diff --git a/core/migrations/__pycache__/0001_initial.cpython-311.pyc b/core/migrations/__pycache__/0001_initial.cpython-311.pyc new file mode 100644 index 0000000..ef1a3a0 Binary files /dev/null and b/core/migrations/__pycache__/0001_initial.cpython-311.pyc differ diff --git a/core/models.py b/core/models.py index 71a8362..035bc75 100644 --- a/core/models.py +++ b/core/models.py @@ -1,3 +1,62 @@ from django.db import models +from django.contrib.auth.models import User +from django.db.models.signals import post_save +from django.dispatch import receiver -# Create your models here. +class Profile(models.Model): + LOCATION_CHOICES = [ + ('Canley', 'Canley'), + ('Leamington Spa', 'Leamington Spa'), + ('On-Campus', 'On-Campus'), + ('Coventry', 'Coventry'), + ('Other', 'Other'), + ] + LOOKING_FOR_CHOICES = [ + ('Friends', 'Friends'), + ('Short-term', 'Short-term'), + ('Long-term', 'Long-term'), + ] + YEAR_CHOICES = [ + ('Year 1', 'Year 1'), + ('Year 2', 'Year 2'), + ('Year 3', 'Year 3'), + ('Year 4+', 'Year 4+'), + ('Postgraduate', 'Postgraduate'), + ] + + user = models.OneToOneField(User, on_delete=models.CASCADE, related_name='profile') + course = models.CharField(max_length=255, blank=True) + year = models.CharField(max_length=50, choices=YEAR_CHOICES, blank=True) + location = models.CharField(max_length=50, choices=LOCATION_CHOICES, blank=True) + looking_for = models.CharField(max_length=50, choices=LOOKING_FOR_CHOICES, blank=True) + bio = models.TextField(max_length=500, blank=True) + is_subscribed = models.BooleanField(default=False) + last_online = models.DateTimeField(auto_now=True) + + def __str__(self): + return f"{self.user.username}'s profile" + + @property + def primary_photo(self): + primary = self.photos.filter(is_primary=True).first() + if primary: + return primary + return self.photos.first() + +class Photo(models.Model): + profile = models.ForeignKey(Profile, on_delete=models.CASCADE, related_name='photos') + image = models.ImageField(upload_to='profile_photos/') + is_primary = models.BooleanField(default=False) + uploaded_at = models.DateTimeField(auto_now_add=True) + + def __str__(self): + return f"Photo for {self.profile.user.username}" + +@receiver(post_save, sender=User) +def create_user_profile(sender, instance, created, **kwargs): + if created: + Profile.objects.create(user=instance) + +@receiver(post_save, sender=User) +def save_user_profile(sender, instance, **kwargs): + instance.profile.save() \ No newline at end of file diff --git a/core/templates/base.html b/core/templates/base.html index 1e7e5fb..140d13b 100644 --- a/core/templates/base.html +++ b/core/templates/base.html @@ -1,25 +1,131 @@ -
- -