Permalink
Browse files

Ch18: NewsLink views use startup_slug URL segment.

  • Loading branch information...
jambonrose committed Apr 30, 2015
1 parent 7dcdf22 commit f4e337f96e46c76e8b6cf93ccf7ab9b31439b987
Showing with 32 additions and 11 deletions.
  1. +7 −6 organizer/forms.py
  2. +14 −1 organizer/utils.py
  3. +11 −4 organizer/views.py
@@ -4,12 +4,6 @@
from .models import NewsLink, Startup, Tag
class NewsLinkForm(forms.ModelForm):
class Meta:
model = NewsLink
fields = '__all__'
class SlugCleanMixin:
"""Mixin class for slug cleaning method."""
@@ -22,6 +16,13 @@ def clean_slug(self):
return new_slug
class NewsLinkForm(
SlugCleanMixin, forms.ModelForm):
class Meta:
model = NewsLink
fields = '__all__'
class StartupForm(
SlugCleanMixin, forms.ModelForm):
class Meta:
@@ -1,6 +1,19 @@
from django.shortcuts import get_object_or_404
from .models import Startup
from .models import NewsLink, Startup
class NewsLinkGetObjectMixin():
def get_object(self, queryset=None):
startup_slug = self.kwargs.get(
self.startup_slug_url_kwarg)
newslink_slug = self.kwargs.get(
self.slug_url_kwarg)
return get_object_or_404(
NewsLink,
slug__iexact=newslink_slug,
startup__slug__iexact=startup_slug)
class PageLinksMixin:
@@ -8,17 +8,22 @@
NewsLinkForm, StartupForm, TagForm)
from .models import NewsLink, Startup, Tag
from .utils import (
PageLinksMixin, StartupContextMixin)
NewsLinkGetObjectMixin, PageLinksMixin,
StartupContextMixin)
class NewsLinkCreate(
StartupContextMixin, CreateView):
NewsLinkGetObjectMixin,
StartupContextMixin,
CreateView):
form_class = NewsLinkForm
model = NewsLink
class NewsLinkDelete(
StartupContextMixin, DeleteView):
NewsLinkGetObjectMixin,
StartupContextMixin,
DeleteView):
model = NewsLink
slug_url_kwarg = 'newslink_slug'
@@ -28,7 +33,9 @@ def get_success_url(self):
class NewsLinkUpdate(
StartupContextMixin, UpdateView):
NewsLinkGetObjectMixin,
StartupContextMixin,
UpdateView):
form_class = NewsLinkForm
model = NewsLink
slug_url_kwarg = 'newslink_slug'

0 comments on commit f4e337f

Please sign in to comment.