-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathmodels.py
More file actions
40 lines (28 loc) · 742 Bytes
/
models.py
File metadata and controls
40 lines (28 loc) · 742 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
from django.db import models
class SortableAbstract(models.Model):
position = models.PositiveIntegerField(
default=0
)
name = models.CharField(
null=True,
blank=True,
max_length=255,
)
class Meta:
abstract = True
def __str__(self):
if not self.name:
return 'Sortable {}'.format(self.pk)
return '{}'.format(self.name)
class SortableParent(SortableAbstract):
class Meta:
abstract = False
ordering = ['position']
class SortableChild(SortableAbstract):
parent = models.ForeignKey(
SortableParent,
on_delete=models.CASCADE,
)
class Meta:
abstract = False
ordering = ['position']