Skip to content

Commit

Permalink
Added views and forms
Browse files Browse the repository at this point in the history
  • Loading branch information
DaniDiazTech committed Jun 3, 2021
1 parent 0a82ca2 commit cb3e069
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 27 deletions.
20 changes: 0 additions & 20 deletions config/photoapp/forms.py
Original file line number Diff line number Diff line change
@@ -1,21 +1 @@
'''Photo app Forms'''

from django import forms

from .models import Photo

class CreatePhotoForm(forms.ModelForm):

class Meta:
model = Photo

fields = ('title', 'description', 'image', 'tags')


class UpdatePhotoForm(forms.ModelForm):

class Meta:
model = Photo

fields = ('title', 'description', 'tags')

12 changes: 5 additions & 7 deletions config/photoapp/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@

from django.core.exceptions import PermissionDenied

from django.urls.resolvers import get_resolver

from django.views.generic import ListView, DetailView, CreateView, UpdateView, DeleteView

from django.contrib.auth.mixins import LoginRequiredMixin, UserPassesTestMixin
Expand All @@ -14,8 +12,6 @@

from .models import Photo

from .forms import CreatePhotoForm, UpdatePhotoForm

class PhotoListView(ListView):

model = Photo
Expand Down Expand Up @@ -53,10 +49,12 @@ class PhotoDetailView(DetailView):

class PhotoCreateView(LoginRequiredMixin, CreateView):

template_name = 'photoapp/create.html'
model = Photo

form_class = CreatePhotoForm
fields = ['title', 'description', 'image', 'tags']

template_name = 'photoapp/create.html'

success_url = reverse_lazy('photo:list')

def form_valid(self, form):
Expand Down Expand Up @@ -84,7 +82,7 @@ class PhotoUpdateView(UserIsSubmitter, UpdateView):

model = Photo

form_class = UpdatePhotoForm
fields = ['title', 'description', 'tags']

success_url = reverse_lazy('photo:list')

Expand Down

0 comments on commit cb3e069

Please sign in to comment.