diff --git a/album/admin.py b/album/admin.py index 0c7ec8c..8a1ed73 100644 --- a/album/admin.py +++ b/album/admin.py @@ -7,4 +7,24 @@ from .models import Album class AlbumAdmin(admin.ModelAdmin): list_display = ['id', 'image', 'is_verified'] + fieldsets = ( + ('General', { + 'fields': ('object_type', 'description', 'image'), + }), + ('User Info', { + 'fields': ( + ('surname', 'first_name'), + ('birth_date','postal_code'), + ('address','town'), + ('telephone','email'), + ), + }), + ('Others', { + 'fields': ( + ('target', 'is_agreed_terms_and_cond'), + 'is_verified' + ), + }) + ) + admin.site.register(Album, AlbumAdmin) diff --git a/album/migrations/0003_album_target.py b/album/migrations/0003_album_target.py new file mode 100644 index 0000000..b9eff76 --- /dev/null +++ b/album/migrations/0003_album_target.py @@ -0,0 +1,19 @@ +# Generated by Django 3.2 on 2022-09-27 22:51 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('album', '0002_auto_20220926_2135'), + ] + + operations = [ + migrations.AddField( + model_name='album', + name='target', + field=models.CharField(choices=[('DONATE_TO_MUSEUM', 'Donate To Museum'), ('MAKE_IT_AVAILABLE_SOLELY', 'Make It Available Solely')], default='', max_length=100), + preserve_default=False, + ), + ] diff --git a/album/models.py b/album/models.py index 2e5cf8d..b0ee4ce 100644 --- a/album/models.py +++ b/album/models.py @@ -12,6 +12,10 @@ class Album(models.Model): MOUNTAIN_STORY = 'MOUNTAIN_STORY' SPECIAL_KNOWLEDGE = 'SPECIAL_KNOWLEDGE' + class TARGET_CHOICES(models.TextChoices): + DONATE_TO_MUSEUM = 'DONATE_TO_MUSEUM' + MAKE_IT_AVAILABLE_SOLELY = 'MAKE_IT_AVAILABLE_SOLELY' + object_type = models.CharField(max_length=40, choices=OBJECT_TYPE_CHOICES.choices) description = models.TextField() image = models.ImageField() @@ -23,6 +27,7 @@ class Album(models.Model): town = models.CharField(max_length=20) telephone = models.CharField(max_length=20) email = models.EmailField() + target = models.CharField(max_length=100, choices=TARGET_CHOICES.choices) is_agreed_terms_and_cond = models.BooleanField() is_verified = models.BooleanField(default=False, blank=True) diff --git a/album/templates/album/homepage.html b/album/templates/album/homepage.html index 7693a1d..34b2500 100644 --- a/album/templates/album/homepage.html +++ b/album/templates/album/homepage.html @@ -2,6 +2,21 @@ {% load humanize %} + +{% block header %} + + +{% endblock header %} + + {% block content %}
@@ -67,7 +82,7 @@ {% endfor %} {% endif %} -
+
+ + diff --git a/album/views.py b/album/views.py index 700c301..ea48444 100644 --- a/album/views.py +++ b/album/views.py @@ -1,12 +1,14 @@ from django.contrib import messages from django.contrib.auth.mixins import LoginRequiredMixin +from django.core import exceptions from django.core.exceptions import PermissionDenied -from django.http import HttpResponse, HttpResponseRedirect +from django.http import (HttpResponse, HttpResponseBadRequest, + HttpResponseRedirect) from django.shortcuts import render from django.views.generic import CreateView, TemplateView -from .models import Album from .forms import AlbumForm +from .models import Album from .serializers import AlbumCreateUpdateSerializer # Create your views here. @@ -20,15 +22,24 @@ class HomePageView(TemplateView): # NOTE: This will be used to update the active window in navbar context.update({ 'contact_us_create': 'active', - 'albums': Album.objects.all() + 'albums': Album.objects.filter(is_verified=True).only('id', 'image', 'is_verified') }) return context def post(self, request, *args, **kwargs) -> HttpResponse: + print(request.POST.get('surname')) form = AlbumForm(request.POST, request.FILES) + # print(form.__dict__) if form.is_valid(): - print(form) + # print('opno') + instance = form.save() + messages.success(self.request, 'Image uploaded successfully.') + + return HttpResponseRedirect('/') + else: + return HttpResponseBadRequest() + # raise exceptions.ValidationError(form.errors) return data = {'image': request.FILES.get('image')} diff --git a/db.sqlite3 b/db.sqlite3 index 634e0b6..68327a5 100644 Binary files a/db.sqlite3 and b/db.sqlite3 differ diff --git a/templates/base.html b/templates/base.html index f0b2797..0f838ca 100644 --- a/templates/base.html +++ b/templates/base.html @@ -22,9 +22,9 @@ - {% block head %} + {% block header %} - {% endblock head %} + {% endblock header %} @@ -44,9 +44,6 @@ - - -