resources, make shortname unique
This commit is contained in:
parent
76b9576f05
commit
e795950e16
|
@ -15,14 +15,18 @@ class ContentParentsInline(admin.TabularInline):
|
|||
model = ContentContent
|
||||
fk_name = 'contentid2'
|
||||
raw_id_fields = ['contentid1']
|
||||
extra = 0
|
||||
|
||||
class ImagesInline(admin.StackedInline):
|
||||
extra = 0
|
||||
model = Image
|
||||
|
||||
class FileInline(admin.StackedInline):
|
||||
extra = 0
|
||||
model = File
|
||||
|
||||
class LinkInline(admin.StackedInline):
|
||||
extra = 0
|
||||
model = Link
|
||||
|
||||
'''
|
||||
|
@ -52,17 +56,12 @@ class ContentAdmin(admin.ModelAdmin):
|
|||
list_display = ('__unicode__', 'datestart', 'shortname', 'type')
|
||||
list_filter = ['datestart', 'type']
|
||||
search_fields = ['title', 'body', 'header', 'shortname']
|
||||
inlines = [ContentParentsInline, ImagesInline, FileInline, LinkInline]
|
||||
inlines = [ContentParentsInline, FileInline, LinkInline]
|
||||
formfield_overrides = {
|
||||
models.TextField: {'widget': AdminMarkdownxWidget},
|
||||
}
|
||||
|
||||
|
||||
# inlines = [SubdomainInline, DomainAliasInline]
|
||||
# list_display = ('url', 'server', 'manage_nameserver', 'domain_registrar', 'email', 'is_active')
|
||||
# list_editable = ('server', 'manage_nameserver', 'domain_registrar', 'email', 'is_active')
|
||||
|
||||
|
||||
admin.site.register(Content, ContentAdmin)
|
||||
admin.site.unregister(Gallery)
|
||||
admin.site.register(Gallery, GalleryAdmin)
|
||||
|
|
22
content/migrations/0007_content_gallery.py
Normal file
22
content/migrations/0007_content_gallery.py
Normal file
|
@ -0,0 +1,22 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
# Generated by Django 1.11.8 on 2017-12-19 13:06
|
||||
from __future__ import unicode_literals
|
||||
|
||||
from django.db import migrations, models
|
||||
import django.db.models.deletion
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('photologue', '0010_auto_20160105_1307'),
|
||||
('content', '0006_auto_20171219_1243'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AddField(
|
||||
model_name='content',
|
||||
name='gallery',
|
||||
field=models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.CASCADE, related_name='content', to='photologue.Gallery'),
|
||||
),
|
||||
]
|
20
content/migrations/0008_auto_20171219_1311.py
Normal file
20
content/migrations/0008_auto_20171219_1311.py
Normal file
|
@ -0,0 +1,20 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
# Generated by Django 1.11.8 on 2017-12-19 13:11
|
||||
from __future__ import unicode_literals
|
||||
|
||||
from django.db import migrations, models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('content', '0007_content_gallery'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AlterField(
|
||||
model_name='content',
|
||||
name='shortname',
|
||||
field=models.CharField(db_column='shortName', max_length=255, unique=True),
|
||||
),
|
||||
]
|
25
content/migrations/0009_auto_20171219_1320.py
Normal file
25
content/migrations/0009_auto_20171219_1320.py
Normal file
|
@ -0,0 +1,25 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
# Generated by Django 1.11.8 on 2017-12-19 13:20
|
||||
from __future__ import unicode_literals
|
||||
|
||||
from django.db import migrations, models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('content', '0008_auto_20171219_1311'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.RenameField(
|
||||
model_name='file',
|
||||
old_name='fil',
|
||||
new_name='file',
|
||||
),
|
||||
migrations.AlterField(
|
||||
model_name='content',
|
||||
name='shortname',
|
||||
field=models.CharField(db_column='shortName', max_length=255, unique=True, verbose_name='Slug'),
|
||||
),
|
||||
]
|
|
@ -62,7 +62,7 @@ class Comments(models.Model): #not used
|
|||
|
||||
class Content(models.Model):
|
||||
type = models.ForeignKey("ContentTypes", db_column="type")
|
||||
shortname = models.CharField(db_column='shortName', max_length=255) # Field name made lowercase.
|
||||
shortname = models.CharField('Slug', db_column='shortName', max_length=255, unique=True)
|
||||
title = models.CharField(max_length=255)
|
||||
header = MarkdownxField(blank=True, null=True, default='')
|
||||
body = MarkdownxField(blank=True, null=True, default='')
|
||||
|
@ -87,6 +87,7 @@ class Content(models.Model):
|
|||
parents = models.ManyToManyField('Content', through='ContentContent', related_name="children")
|
||||
|
||||
resources = models.ManyToManyField('Resources', through='ContentResource', related_name="content")
|
||||
gallery = models.ForeignKey(Gallery, null=True, blank=True, related_name="content")
|
||||
|
||||
# delete after migration
|
||||
parentid = models.IntegerField(null=True, db_column='parentID', blank=True, editable=False)
|
||||
|
@ -123,9 +124,6 @@ class Content(models.Model):
|
|||
if self.image:
|
||||
return settings.IMAGE_PREFIX + self.image
|
||||
|
||||
def links(self):
|
||||
return self.resources.filter(type=3).order_by('orderno')
|
||||
|
||||
def images(self):
|
||||
return self.resources.filter(type=2).exclude(href=self.image).order_by('orderno')
|
||||
|
||||
|
@ -142,16 +140,19 @@ class Content(models.Model):
|
|||
return '/' + '/'.join(parts)
|
||||
|
||||
def get_gallery(self):
|
||||
gallery, created = Gallery.objects.get_or_create(slug=self.shortname)
|
||||
if created:
|
||||
title = self.title
|
||||
n = 1
|
||||
while Gallery.objects.filter(title=title).exclude(pk=gallery.pk).exists():
|
||||
n += 1
|
||||
title = '%s [%s]' % (self.title, n)
|
||||
gallery.title = title
|
||||
gallery.save()
|
||||
return gallery
|
||||
if not self.gallery:
|
||||
gallery, created = Gallery.objects.get_or_create(slug=self.shortname)
|
||||
if created:
|
||||
title = self.title
|
||||
n = 1
|
||||
while Gallery.objects.filter(title=title).exclude(pk=gallery.pk).exists():
|
||||
n += 1
|
||||
title = '%s [%s]' % (self.title, n)
|
||||
gallery.title = title
|
||||
gallery.save()
|
||||
self.gallery = gallery
|
||||
self.save()
|
||||
return self.gallery
|
||||
|
||||
class Meta:
|
||||
managed = True
|
||||
|
@ -307,11 +308,21 @@ class Resources(models.Model):
|
|||
|
||||
class File(models.Model):
|
||||
content = models.ForeignKey('Content')
|
||||
fil = models.FileField(upload_to='files')
|
||||
file = models.FileField(upload_to='files')
|
||||
description = models.TextField(blank=True, null=True)
|
||||
date = models.DateTimeField(auto_now_add=True)
|
||||
order = models.IntegerField(blank=True, null=True)
|
||||
|
||||
class Meta:
|
||||
ordering = ['order', 'file']
|
||||
|
||||
def get_absolute_url(self):
|
||||
return '/' + self.file.name
|
||||
|
||||
@property
|
||||
def name(self):
|
||||
return self.description or self.file.name
|
||||
|
||||
class Image(models.Model):
|
||||
content = models.ForeignKey('Content', related_name='images')
|
||||
image = models.ImageField(upload_to='camp/static/images')
|
||||
|
@ -326,6 +337,9 @@ class Link(models.Model):
|
|||
date = models.DateTimeField(auto_now_add=True)
|
||||
order = models.IntegerField(blank=True, null=True)
|
||||
|
||||
class Meta:
|
||||
ordering = ['order', 'url']
|
||||
|
||||
def __unicode__(self):
|
||||
return self.url
|
||||
|
||||
|
|
|
@ -1,10 +1,22 @@
|
|||
{% if content.links.exists %}
|
||||
{% if content.link_set.exists %}
|
||||
<div class="links">
|
||||
<b>Links:</b>
|
||||
<ul>
|
||||
{% for res in content.links %}
|
||||
{% for link in content.link_set.all %}
|
||||
<li>
|
||||
<a href="{{res.get_absolute_url}}">{{res.description|default:res.href}}</a>
|
||||
<a href="{{link.url}}">{{link.description|default:link.url}}</a>
|
||||
</li>
|
||||
{% endfor %}
|
||||
</ul>
|
||||
</div>
|
||||
{% endif %}
|
||||
{% if content.file_set.exists %}
|
||||
<div class="files">
|
||||
<b>Resources:</b>
|
||||
<ul>
|
||||
{% for file in content.file_set.all %}
|
||||
<li>
|
||||
<a href="{{file.get_absolute_url}}">{{file.name}}</a>
|
||||
</li>
|
||||
{% endfor %}
|
||||
</ul>
|
||||
|
|
Loading…
Reference in New Issue
Block a user