added necessary fields into existing model and made changes in from
This commit is contained in:
parent
030c03b320
commit
e1743be39b
6 changed files with 219 additions and 13 deletions
12
album/forms.py
Normal file
12
album/forms.py
Normal file
|
@ -0,0 +1,12 @@
|
||||||
|
# import form class from django
|
||||||
|
from django import forms
|
||||||
|
|
||||||
|
# import GeeksModel from models.py
|
||||||
|
from .models import Album
|
||||||
|
|
||||||
|
|
||||||
|
# create a ModelForm
|
||||||
|
class AlbumForm(forms.ModelForm):
|
||||||
|
class Meta:
|
||||||
|
model = Album
|
||||||
|
exclude = ('created_at', 'modified_at')
|
83
album/migrations/0002_auto_20220926_2135.py
Normal file
83
album/migrations/0002_auto_20220926_2135.py
Normal file
|
@ -0,0 +1,83 @@
|
||||||
|
# Generated by Django 3.2 on 2022-09-26 21:35
|
||||||
|
|
||||||
|
from django.db import migrations, models
|
||||||
|
|
||||||
|
|
||||||
|
class Migration(migrations.Migration):
|
||||||
|
|
||||||
|
dependencies = [
|
||||||
|
('album', '0001_initial'),
|
||||||
|
]
|
||||||
|
|
||||||
|
operations = [
|
||||||
|
migrations.AlterModelOptions(
|
||||||
|
name='album',
|
||||||
|
options={'ordering': ('-id',), 'verbose_name': 'Album', 'verbose_name_plural': 'Albums'},
|
||||||
|
),
|
||||||
|
migrations.AddField(
|
||||||
|
model_name='album',
|
||||||
|
name='address',
|
||||||
|
field=models.TextField(default=''),
|
||||||
|
preserve_default=False,
|
||||||
|
),
|
||||||
|
migrations.AddField(
|
||||||
|
model_name='album',
|
||||||
|
name='birth_date',
|
||||||
|
field=models.DateField(default='2022-12-12'),
|
||||||
|
preserve_default=False,
|
||||||
|
),
|
||||||
|
migrations.AddField(
|
||||||
|
model_name='album',
|
||||||
|
name='description',
|
||||||
|
field=models.TextField(default=''),
|
||||||
|
preserve_default=False,
|
||||||
|
),
|
||||||
|
migrations.AddField(
|
||||||
|
model_name='album',
|
||||||
|
name='email',
|
||||||
|
field=models.EmailField(default='', max_length=254),
|
||||||
|
preserve_default=False,
|
||||||
|
),
|
||||||
|
migrations.AddField(
|
||||||
|
model_name='album',
|
||||||
|
name='first_name',
|
||||||
|
field=models.CharField(default='', max_length=40),
|
||||||
|
preserve_default=False,
|
||||||
|
),
|
||||||
|
migrations.AddField(
|
||||||
|
model_name='album',
|
||||||
|
name='is_agreed_terms_and_cond',
|
||||||
|
field=models.BooleanField(default=True),
|
||||||
|
preserve_default=False,
|
||||||
|
),
|
||||||
|
migrations.AddField(
|
||||||
|
model_name='album',
|
||||||
|
name='object_type',
|
||||||
|
field=models.CharField(choices=[('EQUIPMENT', 'Equipment'), ('SUMMIT_PHOTO', 'Summit Photo'), ('CLIMBING_FILM', 'Climbing Film'), ('MOUNTAIN_STORY', 'Mountain Story'), ('SPECIAL_KNOWLEDGE', 'Special Knowledge')], default='EQUIPMENT', max_length=40),
|
||||||
|
preserve_default=False,
|
||||||
|
),
|
||||||
|
migrations.AddField(
|
||||||
|
model_name='album',
|
||||||
|
name='postal_code',
|
||||||
|
field=models.CharField(default='2100', max_length=10),
|
||||||
|
preserve_default=False,
|
||||||
|
),
|
||||||
|
migrations.AddField(
|
||||||
|
model_name='album',
|
||||||
|
name='surname',
|
||||||
|
field=models.CharField(default='', max_length=40),
|
||||||
|
preserve_default=False,
|
||||||
|
),
|
||||||
|
migrations.AddField(
|
||||||
|
model_name='album',
|
||||||
|
name='telephone',
|
||||||
|
field=models.CharField(default='', max_length=20),
|
||||||
|
preserve_default=False,
|
||||||
|
),
|
||||||
|
migrations.AddField(
|
||||||
|
model_name='album',
|
||||||
|
name='town',
|
||||||
|
field=models.CharField(default='', max_length=20),
|
||||||
|
preserve_default=False,
|
||||||
|
),
|
||||||
|
]
|
|
@ -5,7 +5,25 @@ from django.utils.translation import gettext_lazy as _
|
||||||
|
|
||||||
|
|
||||||
class Album(models.Model):
|
class Album(models.Model):
|
||||||
|
class OBJECT_TYPE_CHOICES(models.TextChoices):
|
||||||
|
EQUIPMENT = 'EQUIPMENT'
|
||||||
|
SUMMIT_PHOTO = 'SUMMIT_PHOTO'
|
||||||
|
CLIMBING_FILM = 'CLIMBING_FILM'
|
||||||
|
MOUNTAIN_STORY = 'MOUNTAIN_STORY'
|
||||||
|
SPECIAL_KNOWLEDGE = 'SPECIAL_KNOWLEDGE'
|
||||||
|
|
||||||
|
object_type = models.CharField(max_length=40, choices=OBJECT_TYPE_CHOICES.choices)
|
||||||
|
description = models.TextField()
|
||||||
image = models.ImageField()
|
image = models.ImageField()
|
||||||
|
surname = models.CharField(max_length=40)
|
||||||
|
first_name = models.CharField(max_length=40)
|
||||||
|
birth_date = models.DateField()
|
||||||
|
address = models.TextField()
|
||||||
|
postal_code = models.CharField(max_length=10)
|
||||||
|
town = models.CharField(max_length=20)
|
||||||
|
telephone = models.CharField(max_length=20)
|
||||||
|
email = models.EmailField()
|
||||||
|
is_agreed_terms_and_cond = models.BooleanField()
|
||||||
is_verified = models.BooleanField(default=False, blank=True)
|
is_verified = models.BooleanField(default=False, blank=True)
|
||||||
|
|
||||||
# Helpers
|
# Helpers
|
||||||
|
|
|
@ -67,20 +67,108 @@
|
||||||
</div>
|
</div>
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
{% endif %}
|
{% endif %}
|
||||||
<section class="jumbotron text-center">
|
<section class="jumbotron">
|
||||||
<div class="container">
|
<div class="container">
|
||||||
<h1 class="jumbotron-heading">Upload Album Photo</h1>
|
<a class="btn btn-primary" data-toggle="collapse" href="#collapseExample" role="button" aria-expanded="false" aria-controls="collapseExample">
|
||||||
|
Wanna Contribute? click here..
|
||||||
|
</a>
|
||||||
|
<br>
|
||||||
|
<div class="collapse" id="collapseExample">
|
||||||
|
<div class="card card-body mt-3">
|
||||||
<form method="post" enctype="multipart/form-data">
|
<form method="post" enctype="multipart/form-data">
|
||||||
{% csrf_token %}
|
{% csrf_token %}
|
||||||
<div class="input-group">
|
<div class="form-group">
|
||||||
|
<strong>I have ..</strong>
|
||||||
|
<div class="form-check">
|
||||||
|
<input class="form-check-input" type="radio" name="object_type" id="exampleRadios1" value="EQUIPMENT" checked>
|
||||||
|
<label class="form-check-label" for="exampleRadios1">
|
||||||
|
Equipment (helmet; rope; clothing; etc.)
|
||||||
|
</label>
|
||||||
|
</div>
|
||||||
|
<div class="form-check">
|
||||||
|
<input class="form-check-input" type="radio" name="object_type" id="exampleRadios2" value="SUMMIT_PHOTOb">
|
||||||
|
<label class="form-check-label" for="exampleRadios2">
|
||||||
|
Summit photo
|
||||||
|
</label>
|
||||||
|
</div>
|
||||||
|
<div class="form-check">
|
||||||
|
<input class="form-check-input" type="radio" name="object_type" id="exampleRadios3" value="CLIMBING_FILM">
|
||||||
|
<label class="form-check-label" for="exampleRadios3">
|
||||||
|
Climbing film
|
||||||
|
</label>
|
||||||
|
</div>
|
||||||
|
<div class="form-check">
|
||||||
|
<input class="form-check-input" type="radio" name="object_type" id="exampleRadios4" value="MOUNTAIN_STORY">
|
||||||
|
<label class="form-check-label" for="exampleRadios4">
|
||||||
|
Mountain story
|
||||||
|
</label>
|
||||||
|
</div>
|
||||||
|
<div class="form-check">
|
||||||
|
<input class="form-check-input" type="radio" name="object_type" id="exampleRadios5" value="SPECIAL_KNOWLEDGE">
|
||||||
|
<label class="form-check-label" for="exampleRadios5">
|
||||||
|
Special knowledge
|
||||||
|
</label>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div class="form-group">
|
||||||
|
<label for="description"><strong>Description</strong></label>
|
||||||
|
<textarea name="description" id="description" rows="5" class="form-control"></textarea>
|
||||||
|
</div>
|
||||||
|
<div class="form-group">
|
||||||
|
<label for="image"><strong>Image</strong></label>
|
||||||
<div class="custom-file">
|
<div class="custom-file">
|
||||||
<input name="image" type="file" id="image" accept="image/png, image/gif, image/jpeg" >
|
<input name="image" type="file" id="image" accept="image/png, image/gif, image/jpeg" >
|
||||||
<label id="image-label" class="custom-file-label" for="image">Choose an image</label>
|
<label id="image-label" class="custom-file-label" for="image">Choose an image</label>
|
||||||
</div>
|
</div>
|
||||||
<div class="input-group-append">
|
|
||||||
<button class="btn btn-outline-secondary" type="submit">Submit</button>
|
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
<div class="form-group">
|
||||||
|
<label for="surname">Surname</label>
|
||||||
|
<input class="form-control" id="surname" aria-describedby="surname" placeholder="Enter Surname">
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
<div class="form-group">
|
||||||
|
<label for="first_name">First Name</label>
|
||||||
|
<input class="form-control" id="first_name" aria-describedby="first_name" placeholder="Enter First Name">
|
||||||
|
</div>
|
||||||
|
|
||||||
|
|
||||||
|
<div class="form-group">
|
||||||
|
<label for="birth_date">Date of Brith</label>
|
||||||
|
<input type="date" class="form-control" id="birth_date" aria-describedby="first_name" placeholder="Enter surname">
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="form-group">
|
||||||
|
<label for="address">Address</label>
|
||||||
|
<input class="form-control" id="address" aria-describedby="address" placeholder="Enter Address">
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="form-group">
|
||||||
|
<label for="postal_code">Postal Code</label>
|
||||||
|
<input class="form-control" id="postal_code" aria-describedby="postal_code" placeholder="Enter Postal Code">
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="form-group">
|
||||||
|
<label for="town">Town</label>
|
||||||
|
<input class="form-control" id="town" aria-describedby="town" placeholder="Enter Town Name">
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="form-group">
|
||||||
|
<label for="telephone">Telephone</label>
|
||||||
|
<input class="form-control" id="telephone" aria-describedby="telephone" placeholder="Enter Telephone Number">
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="form-group">
|
||||||
|
<label for="email">Email</label>
|
||||||
|
<input type="email" class="form-control" id="email" aria-describedby="email" placeholder="Enter email">
|
||||||
|
<small id="email" class="form-text text-muted">We'll never share your email with anyone else.</small>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<button class="btn btn-primary float-right" type="submit">Submit</button>
|
||||||
|
|
||||||
|
</form>
|
||||||
|
</div>
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
</section>
|
</section>
|
||||||
|
|
||||||
|
|
|
@ -6,6 +6,7 @@ from django.shortcuts import render
|
||||||
from django.views.generic import CreateView, TemplateView
|
from django.views.generic import CreateView, TemplateView
|
||||||
|
|
||||||
from .models import Album
|
from .models import Album
|
||||||
|
from .forms import AlbumForm
|
||||||
from .serializers import AlbumCreateUpdateSerializer
|
from .serializers import AlbumCreateUpdateSerializer
|
||||||
|
|
||||||
# Create your views here.
|
# Create your views here.
|
||||||
|
@ -25,6 +26,10 @@ class HomePageView(TemplateView):
|
||||||
return context
|
return context
|
||||||
|
|
||||||
def post(self, request, *args, **kwargs) -> HttpResponse:
|
def post(self, request, *args, **kwargs) -> HttpResponse:
|
||||||
|
form = AlbumForm(request.POST, request.FILES)
|
||||||
|
if form.is_valid():
|
||||||
|
print(form)
|
||||||
|
return
|
||||||
data = {'image': request.FILES.get('image')}
|
data = {'image': request.FILES.get('image')}
|
||||||
|
|
||||||
serializer = AlbumCreateUpdateSerializer(data=data)
|
serializer = AlbumCreateUpdateSerializer(data=data)
|
||||||
|
|
BIN
db.sqlite3
BIN
db.sqlite3
Binary file not shown.
Loading…
Reference in a new issue