[fix] reorder posts
parent
a43d861c7b
commit
123d89ed79
|
|
@ -0,0 +1,13 @@
|
||||||
|
from django.contrib import admin
|
||||||
|
from admin_ordering.admin import OrderableAdmin
|
||||||
|
from .models import *
|
||||||
|
|
||||||
|
# Register your models here.
|
||||||
|
|
||||||
|
|
||||||
|
@admin.register(Post)
|
||||||
|
class PostModelAdmin(OrderableAdmin, admin.ModelAdmin):
|
||||||
|
list_display = ['title', 'ordering']
|
||||||
|
list_editable = ['ordering']
|
||||||
|
ordering_field_hide_input = True
|
||||||
|
exclude = ['ordering']
|
||||||
|
|
@ -0,0 +1,22 @@
|
||||||
|
# Generated by Django 4.0.5 on 2022-07-25 13:45
|
||||||
|
|
||||||
|
from django.db import migrations, models
|
||||||
|
|
||||||
|
|
||||||
|
class Migration(migrations.Migration):
|
||||||
|
|
||||||
|
dependencies = [
|
||||||
|
('main', '0001_initial'),
|
||||||
|
]
|
||||||
|
|
||||||
|
operations = [
|
||||||
|
migrations.AlterModelOptions(
|
||||||
|
name='post',
|
||||||
|
options={'ordering': ['ordering'], 'verbose_name': 'Ogłoszenie', 'verbose_name_plural': 'Ogłoszenia'},
|
||||||
|
),
|
||||||
|
migrations.AddField(
|
||||||
|
model_name='post',
|
||||||
|
name='ordering',
|
||||||
|
field=models.IntegerField(default=0, verbose_name='Kolejność'),
|
||||||
|
),
|
||||||
|
]
|
||||||
|
|
@ -1,11 +1,12 @@
|
||||||
from django.db import models
|
from django.db import models
|
||||||
from tinymce.models import HTMLField
|
from tinymce.models import HTMLField
|
||||||
|
from admin_ordering.models import OrderableModel
|
||||||
from core.utils import SingletonModel
|
from core.utils import SingletonModel
|
||||||
|
|
||||||
# Create your models here.
|
# Create your models here.
|
||||||
|
|
||||||
|
|
||||||
class Post(models.Model):
|
class Post(OrderableModel):
|
||||||
title = models.CharField('Tytuł', max_length=250)
|
title = models.CharField('Tytuł', max_length=250)
|
||||||
content = HTMLField('Treść')
|
content = HTMLField('Treść')
|
||||||
created_at = models.DateTimeField(auto_now_add=True)
|
created_at = models.DateTimeField(auto_now_add=True)
|
||||||
|
|
@ -13,10 +14,9 @@ class Post(models.Model):
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
return self.title
|
return self.title
|
||||||
|
|
||||||
class Meta:
|
class Meta(OrderableModel.Meta):
|
||||||
verbose_name = 'Ogłoszenie'
|
verbose_name = 'Ogłoszenie'
|
||||||
verbose_name_plural = 'Ogłoszenia'
|
verbose_name_plural = 'Ogłoszenia'
|
||||||
ordering = ['-created_at']
|
|
||||||
|
|
||||||
|
|
||||||
class GrandPrixW(SingletonModel):
|
class GrandPrixW(SingletonModel):
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue