Advertisement
serrggee

staff

Aug 3rd, 2015
225
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #admin.py
  2.  
  3. # -*- coding: utf-8 -*-
  4.  
  5. from django.contrib import admin
  6. from .models import Seniority, StaffMember
  7. class SeniorityAdmin(admin.ModelAdmin):
  8.     pass
  9. admin.site.register(Seniority, SeniorityAdmin)
  10. class StaffMemberAdmin(admin.ModelAdmin):
  11.     pass
  12. admin.site.register(StaffMember, StaffMemberAdmin)
  13.  
  14.  
  15. #model.py
  16.  
  17. # -*- coding: utf-8 -*-
  18. from django.core.urlresolvers import reverse
  19. from django.db import models
  20. from filer.fields.image import FilerImageField
  21. class Seniority(models.Model):
  22.     class Meta:
  23.         app_label = 'staff'
  24.         verbose_name_plural = 'seniorities'
  25.     label = models.CharField(
  26.         u'label',
  27.         blank=False,
  28.         default='',
  29.         help_text=u'Please provide a label for this seniority',
  30.         max_length=64,
  31.         unique=True,
  32.     )
  33.     def __unicode__(self):
  34.         return self.label
  35. class StaffMember(models.Model):
  36.     class Meta:
  37.         app_label = 'staff'
  38.  
  39.     full_name = models.CharField(
  40.         u'full name',
  41.         blank=False,
  42.         default='',
  43.         help_text=u'Please enter a full name for this staff member',
  44.         max_length=64,
  45.         #unique=True,
  46.     )
  47.  
  48.     slug = models.SlugField(
  49.         u'slug',
  50.         blank=False,
  51.         default='',
  52.         help_text=u'Provide a unique slug for this staff member',
  53.         max_length=64,
  54.     )
  55.  
  56.     seniority = models.ForeignKey(
  57.         'staff.Seniority',
  58.         blank=True,
  59.         default=None,
  60.         help_text=u'Please specify a seniority level for this staff member',
  61.         null=True
  62.     )
  63.  
  64.     photo = FilerImageField(
  65.         blank=True,
  66.         help_text=u'Optional. Please supply a photo of this staff member.',
  67.         null=True,
  68.         on_delete=models.SET_NULL,  # Important
  69.     )
  70.     bio = models.TextField(
  71.         'bio',
  72.         blank=True,
  73.         help_text=u"Please provide this staf-member's bio.",
  74.     )
  75.     def absolute_url(self):
  76.         return reverse('staffstaffmember_detail', kwargs={'slug': self.slug, })
  77.  
  78.     def __unicode__(self):
  79.         return self.full_name
  80.  
  81. urls.py
  82.  
  83. # -*- coding: utf-8 -*-
  84.  
  85. from django.conf.urls import patterns, url
  86.  
  87. from .views import StaffListView, StaffDetailView
  88.  
  89.  
  90. urlpatterns = patterns('',
  91.  
  92.     # List View
  93.     url(r'^$', StaffListView.as_view(), name='staffmember_list'),
  94.  
  95.     # Detail View
  96.     url(r'^(?P<slug>[^/]+)/$', StaffDetailView.as_view(), name='staffmember_detail'),
  97. )
  98.  
  99.  
  100. #views.py
  101. # -*- coding: utf-8 -*-
  102. from django.views.generic import DetailView, ListView
  103. from .models import StaffMember
  104. class StaffListView(ListView):
  105.     model = StaffMember
  106.     queryset = StaffMember.objects.all()
  107. class StaffDetailView(DetailView):
  108.     model = StaffMember
  109.     context_object_name = 'staff'
  110.  
  111. #mysite.urls.py  main url
  112.  
  113. url(r'^staff/', include('staff.urls')),
Advertisement
RAW Paste Data Copied
Advertisement