added app collection, added new models
This commit is contained in:
parent
3f5d56fb7a
commit
d24c0cf407
0
apps/collection/__init__.py
Normal file
0
apps/collection/__init__.py
Normal file
19
apps/collection/admin.py
Normal file
19
apps/collection/admin.py
Normal file
|
|
@ -0,0 +1,19 @@
|
||||||
|
from django.contrib.gis import admin
|
||||||
|
|
||||||
|
from collection import models
|
||||||
|
|
||||||
|
|
||||||
|
@admin.register(models.Collection)
|
||||||
|
class CollectionAdmin(admin.ModelAdmin):
|
||||||
|
"""Collection admin."""
|
||||||
|
|
||||||
|
|
||||||
|
@admin.register(models.CollectionItem)
|
||||||
|
class CollectionItemAdmin(admin.ModelAdmin):
|
||||||
|
"""CollectionItem admin."""
|
||||||
|
|
||||||
|
|
||||||
|
@admin.register(models.Guide)
|
||||||
|
class GuideAdmin(admin.ModelAdmin):
|
||||||
|
"""Guide admin."""
|
||||||
|
|
||||||
7
apps/collection/apps.py
Normal file
7
apps/collection/apps.py
Normal file
|
|
@ -0,0 +1,7 @@
|
||||||
|
from django.apps import AppConfig
|
||||||
|
from django.utils.translation import gettext_lazy as _
|
||||||
|
|
||||||
|
|
||||||
|
class CollectionConfig(AppConfig):
|
||||||
|
name = 'collection'
|
||||||
|
verbose_name = _('collection')
|
||||||
0
apps/collection/migrations/__init__.py
Normal file
0
apps/collection/migrations/__init__.py
Normal file
92
apps/collection/models.py
Normal file
92
apps/collection/models.py
Normal file
|
|
@ -0,0 +1,92 @@
|
||||||
|
from django.db import models
|
||||||
|
from django.utils.translation import gettext_lazy as _
|
||||||
|
from django.contrib.postgres.fields import JSONField
|
||||||
|
from utils.models import ProjectBaseMixin
|
||||||
|
|
||||||
|
|
||||||
|
# Mixins
|
||||||
|
class CollectionNameMixin(models.Model):
|
||||||
|
"""CollectionName mixin"""
|
||||||
|
name = models.CharField(_('name'), max_length=250)
|
||||||
|
|
||||||
|
class Meta:
|
||||||
|
"""Meta class"""
|
||||||
|
abstract = True
|
||||||
|
|
||||||
|
|
||||||
|
class CollectionDateMixin(models.Model):
|
||||||
|
"""CollectionDate mixin"""
|
||||||
|
start = models.DateTimeField(_('start'))
|
||||||
|
end = models.DateTimeField(_('end'))
|
||||||
|
|
||||||
|
class Meta:
|
||||||
|
"""Meta class"""
|
||||||
|
abstract = True
|
||||||
|
|
||||||
|
|
||||||
|
# Models
|
||||||
|
class CollectionQuerySet(models.QuerySet):
|
||||||
|
"""QuerySet for model Collection"""
|
||||||
|
|
||||||
|
def by_country(self, country_id):
|
||||||
|
"""Filter collection by country id."""
|
||||||
|
return self.filter(country=country_id)
|
||||||
|
|
||||||
|
|
||||||
|
class Collection(ProjectBaseMixin, CollectionNameMixin, CollectionDateMixin):
|
||||||
|
"""Collection model."""
|
||||||
|
filters = JSONField(
|
||||||
|
_('filters'), null=True, blank=True,
|
||||||
|
default=None, help_text='{"key":"value"}')
|
||||||
|
selectors = JSONField(
|
||||||
|
_('selectors'), null=True, blank=True,
|
||||||
|
default=None, help_text='{"key":"value"}')
|
||||||
|
targets = JSONField(
|
||||||
|
_('targets'), null=True, blank=True,
|
||||||
|
default=None, help_text='{"key":"value"}')
|
||||||
|
country = models.ForeignKey(
|
||||||
|
'location.Country', verbose_name=_('country'), on_delete=models.CASCADE)
|
||||||
|
|
||||||
|
objects = CollectionQuerySet.as_manager()
|
||||||
|
|
||||||
|
|
||||||
|
class CollectionItemQuerySet(models.QuerySet):
|
||||||
|
"""QuerySet for model CollectionItem."""
|
||||||
|
|
||||||
|
def by_collection(self, collection_id):
|
||||||
|
"""Filter by collection id"""
|
||||||
|
return self.filter(collection=collection_id)
|
||||||
|
|
||||||
|
|
||||||
|
class CollectionItem(ProjectBaseMixin):
|
||||||
|
"""CollectionItem model."""
|
||||||
|
collection = models.ForeignKey(
|
||||||
|
Collection, verbose_name=_('collection'), on_delete=models.CASCADE)
|
||||||
|
item_type = models.IntegerField(verbose_name=_('item type identifier'))
|
||||||
|
item_ids = JSONField(
|
||||||
|
_('item_ids'), null=True, blank=True,
|
||||||
|
default=None, help_text='{"key":"value"}')
|
||||||
|
|
||||||
|
objects = CollectionItemQuerySet.as_manager()
|
||||||
|
|
||||||
|
|
||||||
|
class GuideQuerySet(models.QuerySet):
|
||||||
|
"""QuerySet for Guide."""
|
||||||
|
|
||||||
|
def by_collection_id(self, collection_id):
|
||||||
|
"""Filter by collection id"""
|
||||||
|
return self.filter(collection=collection_id)
|
||||||
|
|
||||||
|
|
||||||
|
class Guide(ProjectBaseMixin, CollectionNameMixin, CollectionDateMixin):
|
||||||
|
"""Guide model."""
|
||||||
|
guide_fk = models.ForeignKey(
|
||||||
|
'self', verbose_name=_('guide'), on_delete=models.CASCADE)
|
||||||
|
advertorials = JSONField(
|
||||||
|
_('advertorials'), null=True, blank=True,
|
||||||
|
default=None, help_text='{"key":"value"}')
|
||||||
|
collection = models.ForeignKey(
|
||||||
|
Collection, verbose_name=_('collection'), on_delete=models.CASCADE)
|
||||||
|
|
||||||
|
objects = GuideQuerySet.as_manager()
|
||||||
|
|
||||||
3
apps/collection/tests.py
Normal file
3
apps/collection/tests.py
Normal file
|
|
@ -0,0 +1,3 @@
|
||||||
|
from django.test import TestCase
|
||||||
|
|
||||||
|
# Create your tests here.
|
||||||
3
apps/collection/views.py
Normal file
3
apps/collection/views.py
Normal file
|
|
@ -0,0 +1,3 @@
|
||||||
|
from django.shortcuts import render
|
||||||
|
|
||||||
|
# Create your views here.
|
||||||
|
|
@ -58,6 +58,7 @@ PROJECT_APPS = [
|
||||||
'main.apps.MainConfig',
|
'main.apps.MainConfig',
|
||||||
'news.apps.NewsConfig',
|
'news.apps.NewsConfig',
|
||||||
'translation.apps.TranslationConfig',
|
'translation.apps.TranslationConfig',
|
||||||
|
'collection.apps.CollectionConfig',
|
||||||
]
|
]
|
||||||
|
|
||||||
EXTERNAL_APPS = [
|
EXTERNAL_APPS = [
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user