Created
March 11, 2010 18:21
-
-
Save kennethlove/329475 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
## common/models.py | |
from django.contrib.contenttypes.models import ContentType | |
from django.contrib.contenttypes import generic | |
class CommonFile(models.Model): | |
""" Model for common files. """ | |
content_type = models.ForeignKey(ContentType) | |
object_id = models.PositiveIntegerField() | |
content_object = generic.GenericForeignKey('content_type', 'object_id') | |
order = PositionField(unique_for_field='object_id') | |
title = models.CharField(max_length=255) | |
title.alphabetic_filter = True | |
description = models.TextField(null=True, blank=True) | |
upload = models.FileField(upload_to="uploads/files/") | |
def __unicode__(self): | |
return self.title | |
class Meta: | |
verbose_name = "File" | |
verbose_name_plural = "Files" | |
ordering = ['order',] | |
## common/admin.py | |
from django.contrib.contenttypes import generic | |
class FileInline(generic.GenericStackedInline): | |
model = CommonFile | |
allow_add = True | |
## other_app/admin.py | |
from common.admin import FileInline | |
class OtherModelAdmin(admin.ModelAdmin): | |
inlines = [FileInline,] | |
## other_app/models.py | |
from django.contrib.contenttypes import generic | |
from common.models import CommonFile | |
class OtherModel(models.Model): | |
files = generic.GenericRelation(CommonFile) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment