Commits

Josh VanderLinden  committed 77e200f

Added the attachment model and tied it into the article admin

  • Participants
  • Parent commits c88d5fc
  • Branches article_attachments

Comments (0)

Files changed (2)

File articles/admin.py

 from django.contrib.sites.models import Site
 from django.utils.translation import ugettext_lazy as _
 from forms import ArticleAdminForm
-from models import Tag, Article
+from models import Tag, Article, Attachment
+
+class AttachmentInline(admin.TabularInline):
+    model = Attachment
+    extra = 5
+    max_num = 15
 
 class ArticleAdmin(admin.ModelAdmin):
     list_display = ('title', 'author', 'publish_date', 'expiration_date', 'is_active')
     search_fields = ('title', 'keywords', 'description', 'content')
     date_hierarchy = 'publish_date'
     form = ArticleAdminForm
+    inlines = [
+        AttachmentInline,
+    ]
 
     fieldsets = (
         (None, {'fields': ('title', 'content', 'tags', 'markup')}),

File articles/models.py

     class Meta:
         ordering = ('-publish_date', 'title')
 
+class Attachment(models.Model):
+    upload_to = lambda inst, fn: 'attach/%s/%s/%s' % (datetime.now().year, inst.article.slug, fn)
+
+    article = models.ForeignKey(Article, related_name='attachments')
+    attachment = models.FileField(upload_to=upload_to)
+    caption = models.CharField(max_length=255, blank=True)
+