Add Feedback code
This commit is contained in:
parent
875c2c63d5
commit
c43f3612e3
9 changed files with 149 additions and 11 deletions
|
@ -1,3 +1,11 @@
|
|||
from django.contrib import admin
|
||||
|
||||
# Register your models here.
|
||||
from .models import Feedback
|
||||
|
||||
|
||||
@admin.register(Feedback)
|
||||
class LocationAdmin(admin.ModelAdmin):
|
||||
list_display = ('subject', 'name', 'date', 'message',)
|
||||
list_display_links = ('subject',)
|
||||
search_fields = ('name', 'message', 'subject',)
|
||||
list_per_page = 30
|
||||
|
|
25
contact/forms.py
Normal file
25
contact/forms.py
Normal file
|
@ -0,0 +1,25 @@
|
|||
from django import forms
|
||||
from django.conf import settings
|
||||
from django.core.mail import send_mail
|
||||
|
||||
from .models import Feedback
|
||||
|
||||
|
||||
class FeedbackForm(forms.ModelForm):
|
||||
|
||||
class Meta:
|
||||
model = Feedback
|
||||
exclude = ['ip', 'agent']
|
||||
|
||||
def __init__(self, *args, **kwargs):
|
||||
super(FeedbackForm, self).__init__(*args, **kwargs)
|
||||
self.fields['name'].widget.attrs.update({'class': 'uk-input', 'placeholder': 'Name'})
|
||||
self.fields['email'].widget.attrs.update({'class': 'uk-input', 'placeholder': 'E-mail'})
|
||||
self.fields['subject'].widget.attrs.update({'class': 'uk-input', 'placeholder': 'Subject'})
|
||||
self.fields['message'].widget.attrs.update({'class': 'uk-textarea', 'placeholder': 'Message'})
|
||||
|
||||
def send_email(self):
|
||||
subject = "Gallery Feedback: " + self.cleaned_data['subject']
|
||||
from_email = self.cleaned_data['email']
|
||||
message = self.cleaned_data['message']
|
||||
send_mail(subject, message, from_email, [settings.EMAIL_TO])
|
25
contact/migrations/0001_initial.py
Normal file
25
contact/migrations/0001_initial.py
Normal file
|
@ -0,0 +1,25 @@
|
|||
# Generated by Django 5.1.4 on 2025-02-02 19:12
|
||||
|
||||
from django.db import migrations, models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
initial = True
|
||||
|
||||
dependencies = [
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.CreateModel(
|
||||
name='Feedback',
|
||||
fields=[
|
||||
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
|
||||
('name', models.CharField(max_length=150, verbose_name='Name')),
|
||||
('email', models.EmailField(max_length=150, verbose_name='E-mail')),
|
||||
('date', models.DateTimeField(auto_now_add=True, verbose_name='Sended')),
|
||||
('subject', models.CharField(max_length=150, verbose_name='Subject')),
|
||||
('message', models.TextField(verbose_name='Message')),
|
||||
],
|
||||
),
|
||||
]
|
|
@ -1,3 +1,12 @@
|
|||
from django.db import models
|
||||
|
||||
# Create your models here.
|
||||
|
||||
class Feedback(models.Model):
|
||||
name = models.CharField(max_length=150, verbose_name="Name")
|
||||
email = models.EmailField(max_length=150, verbose_name="E-mail")
|
||||
date = models.DateTimeField(auto_now_add=True, auto_now=False, verbose_name="Sended")
|
||||
subject = models.CharField(max_length=150, verbose_name="Subject")
|
||||
message = models.TextField(verbose_name="Message")
|
||||
|
||||
def __str__(self):
|
||||
return '{}'.format(self.name)
|
||||
|
|
|
@ -3,7 +3,59 @@
|
|||
<!-- Title -->
|
||||
{% block title %} Gallery : Contact {% endblock %}
|
||||
|
||||
<!-- Content -->
|
||||
|
||||
{% block content %}
|
||||
Contact me!
|
||||
|
||||
<div uk-grid>
|
||||
<div class="uk-width-1-1 uk-width-3-4@m">
|
||||
|
||||
<form method='POST'>
|
||||
<fieldset class="uk-fieldset">
|
||||
<legend class="uk-legend">Contact</legend>
|
||||
{% csrf_token %}
|
||||
|
||||
<div class="uk-margin">
|
||||
{{ form.name.errors }}
|
||||
{{ form.name }}
|
||||
</div>
|
||||
|
||||
<div class="uk-margin">
|
||||
{{ form.email.errors }}
|
||||
{{ form.email }}
|
||||
</div>
|
||||
|
||||
<div class="uk-margin">
|
||||
{{ form.subject.errors }}
|
||||
{{ form.subject }}
|
||||
</div>
|
||||
|
||||
<div class="uk-margin">
|
||||
{{ form.message.errors }}
|
||||
{{ form.message }}
|
||||
</div>
|
||||
|
||||
<div class="uk-margin">
|
||||
<input type='submit' value='Send' class="uk-button-primary uk-button-large" />
|
||||
<input type='reset' value='Reset' class="uk-button-default uk-button-large" />
|
||||
</div>
|
||||
|
||||
</fieldset>
|
||||
</form>
|
||||
|
||||
</div>
|
||||
|
||||
<div class="uk-margin-top uk-width-1-4@m uk-visible@m">
|
||||
<div class="uk-card uk-card-default uk-card-body uk-padding-small">
|
||||
{% load static %}
|
||||
<img src="{% static 'img/profile.png' %}" alt="Contact">
|
||||
|
||||
<div class="uk-container uk-margin-small-top">
|
||||
<a href="https://bsky.app/profile/nyymix.net" uk-icon="icon: bluesky"></a>
|
||||
<a href="https://twitter.com/nyymix" uk-icon="icon: twitter"></a>
|
||||
<a href="https://www.instagram.com/nyymix/" uk-icon="icon: instagram"></a>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
{% endblock %}
|
|
@ -5,5 +5,5 @@ from . import views
|
|||
app_name = 'contact'
|
||||
|
||||
urlpatterns = [
|
||||
path('', views.Main.as_view(), name='main_url'),
|
||||
path('', views.Contact.as_view(), name="contact_url")
|
||||
]
|
||||
|
|
|
@ -1,6 +1,25 @@
|
|||
from django.shortcuts import render
|
||||
from django.views.generic import TemplateView
|
||||
from django.contrib import messages
|
||||
from django.shortcuts import redirect, render
|
||||
from django.views.generic.base import View
|
||||
|
||||
from .forms import FeedbackForm
|
||||
from .models import Feedback
|
||||
|
||||
|
||||
class Main(TemplateView):
|
||||
template_name = "contact/main.html"
|
||||
class Contact(View):
|
||||
|
||||
def post(self, request):
|
||||
form = FeedbackForm(request.POST or None)
|
||||
if form.is_valid():
|
||||
profile = form.save(commit=False)
|
||||
profile.save()
|
||||
form.send_email()
|
||||
messages.success(request, 'Your message was sent successfully! Thank you!')
|
||||
return redirect('gallery:main_url')
|
||||
else:
|
||||
messages.warning(request, 'Error occured while sending message.')
|
||||
return render(request, 'contact/main.html', {'form': form})
|
||||
|
||||
def get(self, request):
|
||||
form = FeedbackForm()
|
||||
return render(request, 'contact/main.html', {'form': form})
|
||||
|
|
BIN
static/img/profile.png
Normal file
BIN
static/img/profile.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 30 KiB |
|
@ -37,7 +37,7 @@
|
|||
</div>
|
||||
<div class="uk-navbar-right uk-margin-right">
|
||||
<ul class="uk-navbar-nav">
|
||||
<li class="uk-visible@m"><a href="{% url 'contact:main_url' %}">Contact</a></li>
|
||||
<li class="uk-visible@m"><a href="{% url 'contact:contact_url' %}">Contact</a></li>
|
||||
{% if user.is_authenticated %}
|
||||
<li class="uk-visible@m"><a href="{% url 'admin:index' %}">Admin</a></li>
|
||||
{% endif %}
|
||||
|
@ -55,7 +55,7 @@
|
|||
<li><a href="{% url 'gallery:main_url' %}">Home</a></li>
|
||||
<li><a href="{% url 'gallery:albums_url' %}">Albums</a></li>
|
||||
<li><a href="{% url 'gallery:photos_url' %}">Photostream</a></li>
|
||||
<li><a href="{% url 'contact:main_url' %}">Contact</a></li>
|
||||
<li><a href="{% url 'contact:contact_url' %}">Contact</a></li>
|
||||
{% if user.is_authenticated %}
|
||||
<li><a href="{% url 'admin:index' %}">Admin</a></li>
|
||||
{% endif %}
|
||||
|
|
Loading…
Add table
Reference in a new issue