From 3cce57695de7f7634c82439319d36b8b42512809 Mon Sep 17 00:00:00 2001 From: Pierre-antoine Comby Date: Sun, 11 Aug 2019 23:25:27 +0200 Subject: [PATCH] add basic club management --- apps/member/forms.py | 7 ++++++- apps/member/models.py | 5 ++++- apps/member/urls.py | 5 ++++- apps/member/views.py | 29 ++++++++++++++++++++++++++--- templates/base.html | 2 +- templates/member/club_detail.html | 6 ++++++ templates/member/club_form.html | 11 +++++++++++ templates/member/club_list.html | 17 +++++++++++++++++ 8 files changed, 75 insertions(+), 7 deletions(-) create mode 100644 templates/member/club_detail.html create mode 100644 templates/member/club_form.html create mode 100644 templates/member/club_list.html diff --git a/apps/member/forms.py b/apps/member/forms.py index 9747afd0..e024ee84 100644 --- a/apps/member/forms.py +++ b/apps/member/forms.py @@ -6,7 +6,7 @@ from django.contrib.auth.forms import UserChangeForm, UserCreationForm from django.contrib.auth.models import User from django import forms -from .models import Profile +from .models import Profile, Club class ProfileForm(forms.ModelForm): """ @@ -16,3 +16,8 @@ class ProfileForm(forms.ModelForm): model = Profile fields = '__all__' exclude = ['user'] + +class ClubForm(forms.ModelForm): + class Meta: + model = Club + fields ='__all__' diff --git a/apps/member/models.py b/apps/member/models.py index d2fe75c2..90fb7839 100644 --- a/apps/member/models.py +++ b/apps/member/models.py @@ -7,7 +7,7 @@ from django.db import models from django.db.models.signals import post_save from django.dispatch import receiver from django.utils.translation import gettext_lazy as _ - +from django.urls import reverse class Profile(models.Model): """ @@ -93,6 +93,9 @@ class Club(models.Model): def __str__(self): return self.name + def get_absolute_url(self): + return reverse('member:club_detail', args=(self.pk,)) + class Role(models.Model): """ diff --git a/apps/member/urls.py b/apps/member/urls.py index dbb71374..b5a972a3 100644 --- a/apps/member/urls.py +++ b/apps/member/urls.py @@ -10,5 +10,8 @@ from . import views app_name = 'member' urlpatterns = [ - path('signup/',views.SignUp.as_view(),name="signup") + path('signup/',views.SignUp.as_view(),name="signup"), + path('club/',views.ClubListView.as_view(),name="club_list"), + path('club//',views.ClubDetailView.as_view(),name="club_detail"), + path('club/create/',views.ClubCreateView.as_view(),name="club_create") ] diff --git a/apps/member/views.py b/apps/member/views.py index cc2d2b3f..55fd2fc2 100644 --- a/apps/member/views.py +++ b/apps/member/views.py @@ -5,12 +5,13 @@ from django.contrib.auth.mixins import LoginRequiredMixin from django.utils.translation import gettext_lazy as _ -from django.views.generic.edit import CreateView +from django.views.generic import CreateView, ListView, DetailView from django.http import HttpResponseRedirect from django.contrib.auth.forms import UserCreationForm from django.urls import reverse_lazy -from .models import Profile -from .forms import ProfileForm + +from .models import Profile, Club +from .forms import ProfileForm, ClubForm class SignUp(CreateView): """ @@ -36,3 +37,25 @@ class SignUp(CreateView): user_profile.user = user user_profile.save() return super().form_valid(form) + + +class ClubCreateView(LoginRequiredMixin,CreateView): + """ + Create Club + """ + model = Club + form_class = ClubForm + + def form_valid(self,form): + return super().form_valid(form) + +class ClubListView(LoginRequiredMixin,ListView): + """ + List TransactionsTemplates + """ + model = Club + form_class = ClubForm +class ClubDetailView(LoginRequiredMixin,DetailView): + """ + """ + model = Club diff --git a/templates/base.html b/templates/base.html index 49a46dc8..8e6a2b0e 100644 --- a/templates/base.html +++ b/templates/base.html @@ -31,7 +31,7 @@ Consos