Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Post(models.Model):
- title = models.CharField(max_length=200)
- slug = models.CharField(max_length=200)
- source_url = models.URLField()
- needs_update = models.BooleanField(default=True)
- created = models.DateTimeField(auto_now_add=True)
- updated = models.DateTimeField(auto_now=True)
- #models.py
- class ItemBase(models.Model):
- post = models.ManyToManyField(Post, related_name='%(class)s_related')
- title = models.CharField(max_length=250)
- created = models.DateTimeField(auto_now_add=True)
- updated = models.DateTimeField(auto_now=True)
- class Meta:
- abstract = True
- def __str__(self):
- return self.title
- def render(self):
- return render_to_string('content/items/{}.html'.format(self._meta.model_name), {'item': self})
- class Text(ItemBase):
- content = models.TextField()
- class File(ItemBase):
- file = models.FileField(upload_to='files', blank=True, null=True)
- class Video(ItemBase):
- url = models.URLField()
- class Image(ItemBase):
- image_url = models.URLField(blank=True, null=True)
- image_file = models.ImageField(upload_to='posts/%Y/%m/%d',
- blank=True, null=True)
- #admin.py
- from django.contrib import admin
- from .models import Post
- @admin.register(Post)
- class PostAdmin(admin.ModelAdmin):
- list_display = ['title', 'needs_update', 'created']
- list_filter = ['created', 'needs_update']
- fields = ('title', 'image_related')
Advertisement
Add Comment
Please, Sign In to add comment