-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmodels.py
145 lines (116 loc) · 4.9 KB
/
models.py
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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
from django.db import models
from django.shortcuts import reverse
from django.contrib.contenttypes.fields import GenericRelation
from django.utils.text import slugify
from django.db import IntegrityError, transaction
from apps.images.models import Image
from pure.apps.froala_editor.fields import FroalaField
# from wadibyte.wadicore.models import Image
# from wadibyte.wadimaps.models import City
from taggit.managers import TaggableManager
# from alfuhigi.hash import AlphaID
from alfuhigi import CodeGenerator
from alfuhigi.mixin import QuerySetMixin
from alfuhigi.models import ActiveAbstract, UUIdAbstract
from .choices import KIND_CHOICES
# Create your models here.
#.
class SehhaQuerySet(models.QuerySet, QuerySetMixin):
pass
# def disp(self):
# return self.filter(kind=1)
# def hosp(self):
# return self.filter(kind=2)
class Organization(ActiveAbstract, UUIdAbstract):
objects = SehhaQuerySet.as_manager()
name = models.CharField(max_length=100, null=True)
slug = models.SlugField(null=True, editable=False, unique=True)
phone = models.CharField(max_length=100, null=True,)
fax = models.CharField(max_length=100, null=True, blank=True)
email = models.EmailField()
images = GenericRelation(Image)
address = models.CharField(max_length=100, null=True)
lat = models.CharField(max_length=20, null=True)
lng = models.CharField(max_length=20, null=True)
content = models.TextField(null=True, blank=True)
working_time = models.CharField(max_length=100, null=True, blank=True)
tags = TaggableManager()
class Meta:
pass
# app_label = 'org'
permissions = (
('can_view_odd_ids', 'can_view_odd_ids'),
('can_view_even_ids', 'can_view_even_ids'),
)
def save(self, *args, **kwargs):
if self.pk is None:
self.uuid = self.code_generate(Organization, size=9)
self.slug = slugify(self.name, allow_unicode=True)
super(Organization, self).save(*args, **kwargs)
# with transaction.atomic():
# super(Organization,self).save(*args,**kwargs)
def as_dic(self):
return {
'name': self.name,
'slug': self.slug,
'phone': self.phone,
'fax': self.fax,
'email': self.email,
'address': self.address,
'lat': self.lat,
'lng': self.lng,
'content': self.content,
'working_time': self.working_time
}
def get_list_url(self):
return reverse('org-list')
def get_create_url(self):
return reverse('org-create')
def get_absolute_url(self):
return reverse('org-detail', kwargs={'slug': self.slug, 'uuid': self.uuid})
def get_update_url(self):
return reverse('org-update', kwargs={'uuid': self.uuid})
def get_delete_url(self):
return reverse('org-delete', kwargs={'uuid': self.uuid})
def __str__(self):
return '{} '.format(self.name) or None
class Unit(models.Model):
organization = models.ForeignKey(to='Organization', blank=True,
related_name='unit')
name = models.CharField(max_length=100, null=True, blank=True)
image = models.ForeignKey(Image, null=True, blank=True)
working_time = models.CharField(max_length=100, null=True, blank=True)
phone = models.CharField(max_length=100, null=True, blank=True)
fax = models.CharField(max_length=100, null=True, blank=True)
email = models.EmailField()
def __str__(self):
return 'Organization:{}, Unit:{}'.format(self.organization.name,
self.name)
class Page(ActiveAbstract, UUIdAbstract):
objects = SehhaQuerySet.as_manager()
title = models.CharField(max_length=100, null=True)
subtitle = models.CharField(max_length=100, null=True, blank=True)
slug = models.SlugField(null=True, blank=True, editable=False)
thumbnail = models.ForeignKey(Image, null=True, blank=True)
org = models.ForeignKey(to='Organization', null=True, blank=True,
related_name='page_org')
tags = TaggableManager()
body = models.TextField()
def save(self, *args, **kwargs):
if self.pk is None:
self.uuid = self.code_generate(model=Page, size=4,
mod='mixcase_digits')
self.slug = slugify(self.title, allow_unicode=True)
super(Page, self).save(*args, **kwargs)
def __str__(self):
return self.title
def get_list_url(self):
return reverse('news-list')
def get_create_url(self):
return reverse('news-create')
def get_absolute_url(self):
return reverse('news-detail', kwargs={'pk': self.pk})
def get_update_url(self):
return reverse('news-update', kwargs={'pk': self.pk})
def get_delete_url(self):
return reverse('news-delete', kwargs={'pk': self.pk})