add awards

This commit is contained in:
Dmitriy Kuzmenko 2019-08-28 10:15:17 +03:00
parent a35fbc4456
commit 262e98b9e1
31 changed files with 255 additions and 2 deletions

View File

@ -1,4 +1,18 @@
"""Establishment admin conf."""
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."""

View File

@ -5,6 +5,7 @@ from django.db import models
from django.utils.translation import gettext_lazy as _
from location.models import Address
from utils.models import ProjectBaseMixin, ImageMixin, LocaleManagerMixin
from django.contrib.contenttypes import fields as generic
# todo: establishment type&subtypes check
@ -91,6 +92,7 @@ class Establishment(ProjectBaseMixin, ImageMixin):
price_level = models.PositiveIntegerField(blank=True, null=True,
default=None,
verbose_name=_('Price level'))
awards = generic.GenericRelation(to='main.Award')
objects = EstablishmentManager()

View File

@ -11,3 +11,15 @@ class SiteSettingsAdmin(admin.ModelAdmin):
@admin.register(models.Feature)
class FeatureAdmin(admin.ModelAdmin):
"""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__']

View 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')),
],
),
]

View 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 = [
]

View 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',
),
]

View 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'),
),
]

View File

@ -1,9 +1,10 @@
"""Main app models."""
from django.conf import settings
from django.contrib.contenttypes import fields as generic
from django.contrib.postgres.fields import JSONField
from django.db import models
from django.utils.translation import gettext_lazy as _
from django.contrib.contenttypes.models import ContentType
from location.models import Country
from main import methods
from utils.models import ProjectBaseMixin
@ -182,3 +183,29 @@ class SiteFeature(ProjectBaseMixin):
verbose_name = _('Site feature')
verbose_name_plural = _('Site features')
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)

View File

@ -68,3 +68,15 @@ class SiteSettingsSerializer(serializers.ModelSerializer):
# 'site_settings',
# 'feature',
# )
class AwardSerializer(serializers.ModelSerializer):
"""Award serializer."""
class Meta:
model = models.Award
fields = [
# 'title',
'award_type',
'vintage_year',
]

View File

@ -17,4 +17,6 @@ urlpatterns = [
# name='site-features-lc'),
# path('site-features/<int:pk>/', views.SiteFeaturesRUDView.as_view(),
# name='site-features-rud'),
path('awards/', views.AwardView.as_view(), name='awards_list', ),
path('awards/<int:pk>/', views.AwardRetrieveView.as_view(), name='awards_retrieve', ),
]

View File

@ -60,3 +60,17 @@ class SiteSettingsView(generics.RetrieveAPIView):
# class SiteFeaturesRUDView(SiteFeaturesViewMixin,
# generics.RetrieveUpdateDestroyAPIView):
# """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,)

View File

@ -1,6 +1,7 @@
from django.contrib.postgres.fields import JSONField
from django.db import models
from django.utils.translation import gettext_lazy as _
from django.utils.translation import get_language
from utils.models import (ProjectBaseMixin, BaseAttributes,
LocaleManagerMixin, ImageMixin)
@ -80,3 +81,8 @@ class News(BaseAttributes):
def __str__(self):
return f'news: {self.id}'
@property
def test_trans(self):
language = get_language()
return self.title.get(language)

View File

3
apps/products/admin.py Normal file
View File

@ -0,0 +1,3 @@
from django.contrib import admin
# Register your models here.

8
apps/products/apps.py Normal file
View 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')

View File

63
apps/products/models.py Normal file
View 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')

View File

View File

@ -0,0 +1 @@
from rest_framework import serializers

View File

View File

3
apps/products/tests.py Normal file
View File

@ -0,0 +1,3 @@
from django.test import TestCase
# Create your tests here.

View File

View File

View File

View File

View File

View File

View File

View File

@ -0,0 +1 @@
# Create your views here.

View File