add awards
This commit is contained in:
parent
a35fbc4456
commit
262e98b9e1
|
|
@ -1,4 +1,18 @@
|
||||||
"""Establishment admin conf."""
|
"""Establishment admin conf."""
|
||||||
from django.contrib import admin
|
from django.contrib import admin
|
||||||
|
from establishment import models
|
||||||
|
|
||||||
# Register your models here.
|
|
||||||
|
@admin.register(models.EstablishmentType)
|
||||||
|
class EstablishmentTypeAdmin(admin.ModelAdmin):
|
||||||
|
"""EstablishmentType admin."""
|
||||||
|
|
||||||
|
|
||||||
|
@admin.register(models.EstablishmentSubType)
|
||||||
|
class EstablishmentSubTypeAdmin(admin.ModelAdmin):
|
||||||
|
"""EstablishmentSubType admin."""
|
||||||
|
|
||||||
|
|
||||||
|
@admin.register(models.Establishment)
|
||||||
|
class EstablishmentAdmin(admin.ModelAdmin):
|
||||||
|
"""Establishment admin."""
|
||||||
|
|
|
||||||
|
|
@ -5,6 +5,7 @@ from django.db import models
|
||||||
from django.utils.translation import gettext_lazy as _
|
from django.utils.translation import gettext_lazy as _
|
||||||
from location.models import Address
|
from location.models import Address
|
||||||
from utils.models import ProjectBaseMixin, ImageMixin, LocaleManagerMixin
|
from utils.models import ProjectBaseMixin, ImageMixin, LocaleManagerMixin
|
||||||
|
from django.contrib.contenttypes import fields as generic
|
||||||
|
|
||||||
|
|
||||||
# todo: establishment type&subtypes check
|
# todo: establishment type&subtypes check
|
||||||
|
|
@ -91,6 +92,7 @@ class Establishment(ProjectBaseMixin, ImageMixin):
|
||||||
price_level = models.PositiveIntegerField(blank=True, null=True,
|
price_level = models.PositiveIntegerField(blank=True, null=True,
|
||||||
default=None,
|
default=None,
|
||||||
verbose_name=_('Price level'))
|
verbose_name=_('Price level'))
|
||||||
|
awards = generic.GenericRelation(to='main.Award')
|
||||||
|
|
||||||
objects = EstablishmentManager()
|
objects = EstablishmentManager()
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -11,3 +11,15 @@ class SiteSettingsAdmin(admin.ModelAdmin):
|
||||||
@admin.register(models.Feature)
|
@admin.register(models.Feature)
|
||||||
class FeatureAdmin(admin.ModelAdmin):
|
class FeatureAdmin(admin.ModelAdmin):
|
||||||
"""Feature admin conf."""
|
"""Feature admin conf."""
|
||||||
|
|
||||||
|
|
||||||
|
@admin.register(models.AwardType)
|
||||||
|
class AwardTypeAdmin(admin.ModelAdmin):
|
||||||
|
"""Award type admin conf."""
|
||||||
|
|
||||||
|
|
||||||
|
@admin.register(models.Award)
|
||||||
|
class AwardAdmin(admin.ModelAdmin):
|
||||||
|
"""Award admin conf."""
|
||||||
|
# list_display = ['id', '__str__']
|
||||||
|
# list_display_links = ['id', '__str__']
|
||||||
|
|
|
||||||
35
apps/main/migrations/0007_award_awardtype.py
Normal file
35
apps/main/migrations/0007_award_awardtype.py
Normal file
|
|
@ -0,0 +1,35 @@
|
||||||
|
# Generated by Django 2.2.4 on 2019-08-27 13:46
|
||||||
|
|
||||||
|
from django.db import migrations, models
|
||||||
|
import django.db.models.deletion
|
||||||
|
|
||||||
|
|
||||||
|
class Migration(migrations.Migration):
|
||||||
|
|
||||||
|
dependencies = [
|
||||||
|
('location', '0005_auto_20190822_1144'),
|
||||||
|
('contenttypes', '0002_remove_content_type_name'),
|
||||||
|
('main', '0006_auto_20190822_1118'),
|
||||||
|
]
|
||||||
|
|
||||||
|
operations = [
|
||||||
|
migrations.CreateModel(
|
||||||
|
name='AwardType',
|
||||||
|
fields=[
|
||||||
|
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
|
||||||
|
('name', models.CharField(max_length=255, verbose_name='name')),
|
||||||
|
('country', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='location.Country', verbose_name='country')),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
migrations.CreateModel(
|
||||||
|
name='Award',
|
||||||
|
fields=[
|
||||||
|
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
|
||||||
|
('title', models.CharField(default='', max_length=255, verbose_name='title')),
|
||||||
|
('vintage_year', models.CharField(default='', max_length=255, verbose_name='vintage year')),
|
||||||
|
('object_id', models.PositiveIntegerField()),
|
||||||
|
('award_type', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='main.AwardType')),
|
||||||
|
('content_type', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='contenttypes.ContentType')),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
]
|
||||||
14
apps/main/migrations/0008_merge_20190827_1433.py
Normal file
14
apps/main/migrations/0008_merge_20190827_1433.py
Normal file
|
|
@ -0,0 +1,14 @@
|
||||||
|
# Generated by Django 2.2.4 on 2019-08-27 14:33
|
||||||
|
|
||||||
|
from django.db import migrations
|
||||||
|
|
||||||
|
|
||||||
|
class Migration(migrations.Migration):
|
||||||
|
|
||||||
|
dependencies = [
|
||||||
|
('main', '0007_award_awardtype'),
|
||||||
|
('main', '0007_sitefeature_main'),
|
||||||
|
]
|
||||||
|
|
||||||
|
operations = [
|
||||||
|
]
|
||||||
17
apps/main/migrations/0009_remove_award_title.py
Normal file
17
apps/main/migrations/0009_remove_award_title.py
Normal file
|
|
@ -0,0 +1,17 @@
|
||||||
|
# Generated by Django 2.2.4 on 2019-08-28 07:03
|
||||||
|
|
||||||
|
from django.db import migrations
|
||||||
|
|
||||||
|
|
||||||
|
class Migration(migrations.Migration):
|
||||||
|
|
||||||
|
dependencies = [
|
||||||
|
('main', '0008_merge_20190827_1433'),
|
||||||
|
]
|
||||||
|
|
||||||
|
operations = [
|
||||||
|
migrations.RemoveField(
|
||||||
|
model_name='award',
|
||||||
|
name='title',
|
||||||
|
),
|
||||||
|
]
|
||||||
19
apps/main/migrations/0010_award_title.py
Normal file
19
apps/main/migrations/0010_award_title.py
Normal file
|
|
@ -0,0 +1,19 @@
|
||||||
|
# Generated by Django 2.2.4 on 2019-08-28 07:05
|
||||||
|
|
||||||
|
import django.contrib.postgres.fields.jsonb
|
||||||
|
from django.db import migrations
|
||||||
|
|
||||||
|
|
||||||
|
class Migration(migrations.Migration):
|
||||||
|
|
||||||
|
dependencies = [
|
||||||
|
('main', '0009_remove_award_title'),
|
||||||
|
]
|
||||||
|
|
||||||
|
operations = [
|
||||||
|
migrations.AddField(
|
||||||
|
model_name='award',
|
||||||
|
name='title',
|
||||||
|
field=django.contrib.postgres.fields.jsonb.JSONField(blank=True, default=None, help_text='{"en":"some text"}', null=True, verbose_name='title'),
|
||||||
|
),
|
||||||
|
]
|
||||||
|
|
@ -1,9 +1,10 @@
|
||||||
"""Main app models."""
|
"""Main app models."""
|
||||||
from django.conf import settings
|
from django.conf import settings
|
||||||
|
from django.contrib.contenttypes import fields as generic
|
||||||
from django.contrib.postgres.fields import JSONField
|
from django.contrib.postgres.fields import JSONField
|
||||||
from django.db import models
|
from django.db import models
|
||||||
from django.utils.translation import gettext_lazy as _
|
from django.utils.translation import gettext_lazy as _
|
||||||
|
from django.contrib.contenttypes.models import ContentType
|
||||||
from location.models import Country
|
from location.models import Country
|
||||||
from main import methods
|
from main import methods
|
||||||
from utils.models import ProjectBaseMixin
|
from utils.models import ProjectBaseMixin
|
||||||
|
|
@ -182,3 +183,29 @@ class SiteFeature(ProjectBaseMixin):
|
||||||
verbose_name = _('Site feature')
|
verbose_name = _('Site feature')
|
||||||
verbose_name_plural = _('Site features')
|
verbose_name_plural = _('Site features')
|
||||||
unique_together = ('site_settings', 'feature')
|
unique_together = ('site_settings', 'feature')
|
||||||
|
|
||||||
|
|
||||||
|
class Award(models.Model):
|
||||||
|
"""Award model."""
|
||||||
|
award_type = models.ForeignKey('main.AwardType', on_delete=models.CASCADE)
|
||||||
|
title = JSONField(
|
||||||
|
_('title'), null=True, blank=True,
|
||||||
|
default=None, help_text='{"en":"some text"}')
|
||||||
|
vintage_year = models.CharField(_('vintage year'), max_length=255, default='')
|
||||||
|
|
||||||
|
content_type = models.ForeignKey(ContentType, on_delete=models.CASCADE)
|
||||||
|
object_id = models.PositiveIntegerField()
|
||||||
|
content_object = generic.GenericForeignKey('content_type', 'object_id')
|
||||||
|
|
||||||
|
def __str__(self):
|
||||||
|
title = 'None'
|
||||||
|
if self.title and 'en' in self.title:
|
||||||
|
title = self.title['en']
|
||||||
|
return f'id:{self.id}-{title}'
|
||||||
|
|
||||||
|
|
||||||
|
class AwardType(models.Model):
|
||||||
|
"""AwardType model."""
|
||||||
|
country = models.ForeignKey(
|
||||||
|
'location.Country', verbose_name=_('country'), on_delete=models.CASCADE)
|
||||||
|
name = models.CharField(_('name'), max_length=255)
|
||||||
|
|
|
||||||
|
|
@ -68,3 +68,15 @@ class SiteSettingsSerializer(serializers.ModelSerializer):
|
||||||
# 'site_settings',
|
# 'site_settings',
|
||||||
# 'feature',
|
# 'feature',
|
||||||
# )
|
# )
|
||||||
|
|
||||||
|
|
||||||
|
class AwardSerializer(serializers.ModelSerializer):
|
||||||
|
"""Award serializer."""
|
||||||
|
|
||||||
|
class Meta:
|
||||||
|
model = models.Award
|
||||||
|
fields = [
|
||||||
|
# 'title',
|
||||||
|
'award_type',
|
||||||
|
'vintage_year',
|
||||||
|
]
|
||||||
|
|
@ -17,4 +17,6 @@ urlpatterns = [
|
||||||
# name='site-features-lc'),
|
# name='site-features-lc'),
|
||||||
# path('site-features/<int:pk>/', views.SiteFeaturesRUDView.as_view(),
|
# path('site-features/<int:pk>/', views.SiteFeaturesRUDView.as_view(),
|
||||||
# name='site-features-rud'),
|
# name='site-features-rud'),
|
||||||
|
path('awards/', views.AwardView.as_view(), name='awards_list', ),
|
||||||
|
path('awards/<int:pk>/', views.AwardRetrieveView.as_view(), name='awards_retrieve', ),
|
||||||
]
|
]
|
||||||
|
|
@ -60,3 +60,17 @@ class SiteSettingsView(generics.RetrieveAPIView):
|
||||||
# class SiteFeaturesRUDView(SiteFeaturesViewMixin,
|
# class SiteFeaturesRUDView(SiteFeaturesViewMixin,
|
||||||
# generics.RetrieveUpdateDestroyAPIView):
|
# generics.RetrieveUpdateDestroyAPIView):
|
||||||
# """Site features RUD."""
|
# """Site features RUD."""
|
||||||
|
|
||||||
|
|
||||||
|
class AwardView(generics.ListAPIView):
|
||||||
|
"""Awards list view."""
|
||||||
|
serializer_class = serializers.AwardSerializer
|
||||||
|
queryset = models.Award.objects.all()
|
||||||
|
permission_classes = (permissions.AllowAny, )
|
||||||
|
|
||||||
|
|
||||||
|
class AwardRetrieveView(generics.RetrieveUpdateDestroyAPIView):
|
||||||
|
"""Award retrieve view."""
|
||||||
|
serializer_class = serializers.AwardSerializer
|
||||||
|
queryset = models.Award.objects.all()
|
||||||
|
permission_classes = (permissions.IsAuthenticatedOrReadOnly,)
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,7 @@
|
||||||
from django.contrib.postgres.fields import JSONField
|
from django.contrib.postgres.fields import JSONField
|
||||||
from django.db import models
|
from django.db import models
|
||||||
from django.utils.translation import gettext_lazy as _
|
from django.utils.translation import gettext_lazy as _
|
||||||
|
from django.utils.translation import get_language
|
||||||
|
|
||||||
from utils.models import (ProjectBaseMixin, BaseAttributes,
|
from utils.models import (ProjectBaseMixin, BaseAttributes,
|
||||||
LocaleManagerMixin, ImageMixin)
|
LocaleManagerMixin, ImageMixin)
|
||||||
|
|
@ -80,3 +81,8 @@ class News(BaseAttributes):
|
||||||
|
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
return f'news: {self.id}'
|
return f'news: {self.id}'
|
||||||
|
|
||||||
|
@property
|
||||||
|
def test_trans(self):
|
||||||
|
language = get_language()
|
||||||
|
return self.title.get(language)
|
||||||
|
|
|
||||||
0
apps/products/__init__.py
Normal file
0
apps/products/__init__.py
Normal file
3
apps/products/admin.py
Normal file
3
apps/products/admin.py
Normal file
|
|
@ -0,0 +1,3 @@
|
||||||
|
from django.contrib import admin
|
||||||
|
|
||||||
|
# Register your models here.
|
||||||
8
apps/products/apps.py
Normal file
8
apps/products/apps.py
Normal file
|
|
@ -0,0 +1,8 @@
|
||||||
|
from django.apps import AppConfig
|
||||||
|
from django.utils.translation import gettext_lazy as _
|
||||||
|
|
||||||
|
|
||||||
|
class ProductsConfig(AppConfig):
|
||||||
|
"""Products model."""
|
||||||
|
name = 'products'
|
||||||
|
verbose_name = _('products')
|
||||||
0
apps/products/migrations/__init__.py
Normal file
0
apps/products/migrations/__init__.py
Normal file
63
apps/products/models.py
Normal file
63
apps/products/models.py
Normal file
|
|
@ -0,0 +1,63 @@
|
||||||
|
# from django.contrib.postgres.fields import JSONField
|
||||||
|
# from django.db import models
|
||||||
|
# from django.utils.translation import gettext_lazy as _
|
||||||
|
#
|
||||||
|
# from utils.models import BaseAttributes
|
||||||
|
#
|
||||||
|
#
|
||||||
|
# class ProductManager(models.Manager):
|
||||||
|
# """Product manager."""
|
||||||
|
#
|
||||||
|
#
|
||||||
|
# class ProductQuerySet(models.QuerySet):
|
||||||
|
# """Product queryset."""
|
||||||
|
#
|
||||||
|
#
|
||||||
|
# class Product(BaseAttributes):
|
||||||
|
# """Product models."""
|
||||||
|
# name = models.CharField(_('name'), max_length=255)
|
||||||
|
# country = models.ForeignKey('location.Country', on_delete=models.CASCADE)
|
||||||
|
# region = models.ForeignKey('location.Region', on_delete=models.CASCADE)
|
||||||
|
# # ASK: What is the "subregion"
|
||||||
|
#
|
||||||
|
# description = JSONField(_('description'))
|
||||||
|
# characteristics = JSONField(_('characteristics'))
|
||||||
|
# metadata_values = JSONField(_('metadata_values'))
|
||||||
|
# # common_relations_id
|
||||||
|
# # product_region_id
|
||||||
|
# code = models.CharField(_('code'), max_length=255)
|
||||||
|
# available = models.BooleanField(_('available'))
|
||||||
|
#
|
||||||
|
# # dealer_type
|
||||||
|
# # target_scope
|
||||||
|
# # target_type
|
||||||
|
# # rank
|
||||||
|
# # excluding_tax_unit_price
|
||||||
|
# # column_21
|
||||||
|
# # currencies_id
|
||||||
|
# # vintage
|
||||||
|
# # producer_price
|
||||||
|
# # producer_description
|
||||||
|
# # annual_produced_quantity
|
||||||
|
# # production_method_description
|
||||||
|
# # unit_name
|
||||||
|
# # unit
|
||||||
|
# # unit_values
|
||||||
|
# # organic_source
|
||||||
|
# # certificates
|
||||||
|
# # establishments_id
|
||||||
|
# # restrictions
|
||||||
|
# #
|
||||||
|
# objects = ProductManager.from_queryset(ProductQuerySet)()
|
||||||
|
#
|
||||||
|
# class Meta:
|
||||||
|
# verbose_name = _('product')
|
||||||
|
# verbose_name_plural = _('products')
|
||||||
|
#
|
||||||
|
#
|
||||||
|
# class ProductType(models.Model):
|
||||||
|
# """ProductType model."""
|
||||||
|
#
|
||||||
|
# class Meta:
|
||||||
|
# verbose_name_plural = _('product types')
|
||||||
|
# verbose_name = _('product type')
|
||||||
0
apps/products/serializers/__init__.py
Normal file
0
apps/products/serializers/__init__.py
Normal file
1
apps/products/serializers/common.py
Normal file
1
apps/products/serializers/common.py
Normal file
|
|
@ -0,0 +1 @@
|
||||||
|
from rest_framework import serializers
|
||||||
0
apps/products/serializers/mobile.py
Normal file
0
apps/products/serializers/mobile.py
Normal file
0
apps/products/serializers/web.py
Normal file
0
apps/products/serializers/web.py
Normal file
3
apps/products/tests.py
Normal file
3
apps/products/tests.py
Normal file
|
|
@ -0,0 +1,3 @@
|
||||||
|
from django.test import TestCase
|
||||||
|
|
||||||
|
# Create your tests here.
|
||||||
0
apps/products/urls/__init__.py
Normal file
0
apps/products/urls/__init__.py
Normal file
0
apps/products/urls/common.py
Normal file
0
apps/products/urls/common.py
Normal file
0
apps/products/urls/mobile.py
Normal file
0
apps/products/urls/mobile.py
Normal file
0
apps/products/urls/web.py
Normal file
0
apps/products/urls/web.py
Normal file
0
apps/products/views/__init__.py
Normal file
0
apps/products/views/__init__.py
Normal file
0
apps/products/views/common.py
Normal file
0
apps/products/views/common.py
Normal file
0
apps/products/views/mobile.py
Normal file
0
apps/products/views/mobile.py
Normal file
1
apps/products/views/views.py
Normal file
1
apps/products/views/views.py
Normal file
|
|
@ -0,0 +1 @@
|
||||||
|
# Create your views here.
|
||||||
0
apps/products/views/web.py
Normal file
0
apps/products/views/web.py
Normal file
Loading…
Reference in New Issue
Block a user