Skip to content

Commit

Permalink
feature: Расширен функционал для работы с зоной администратора (#19)
Browse files Browse the repository at this point in the history
Пока убрал Предпочтения в рамках амбассадорства. Если надо будет вернём.
Расширил админ зону
  • Loading branch information
Diavolution authored Mar 7, 2024
2 parents 7c2c1e2 + b3e2454 commit e3245e8
Show file tree
Hide file tree
Showing 4 changed files with 59 additions and 77 deletions.
64 changes: 54 additions & 10 deletions crm_yandex/ambassadors/admin.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,59 @@
from django.contrib import admin

from .models import (Activity, Ambassador, AmbassadorActivity,
AmbassadorPreference, Content, MerchOnShipping,
MerchShipment, Preference, Venue)
from .models import (Activity, Ambassador, AmbassadorActivity, Content, Merch,
MerchOnShipping, MerchShipment, Venue)

admin.site.register(Activity)
admin.site.register(Ambassador)

class AmbassadorActivityInline(admin.TabularInline):
model = AmbassadorActivity
extra = 1


class MerchOnShippingInline(admin.TabularInline):
model = MerchOnShipping
extra = 1


class ActivityAdmin(admin.ModelAdmin):
list_display = ("name",)
empty_value_display = "-пусто"


class MerchAdmin(admin.ModelAdmin):
list_display = ("merch_type", "cost")
empty_value_display = "-пусто"


class VenueAdmin(admin.ModelAdmin):
list_display = ("name",)
empty_value_display = "-пусто"


class MerchShipmentAdmin(admin.ModelAdmin):
list_display = ("curator", "ambassador", "status", "date")
list_filter = ("status", "ambassador", "curator")
inlines = (MerchOnShippingInline,)
empty_value_display = "-пусто"


class ContentAdmin(admin.ModelAdmin):
list_display = ("ambassador", "link", "date", "guide_followed")
list_filter = ("ambassador", "venue", "guide_followed")
empty_value_display = "-пусто"


class AmbassadorAdmin(admin.ModelAdmin):
list_display = ("fio", "telegram", "promocode", "status")
list_filter = ("fio", "status")
inlines = (AmbassadorActivityInline,)
empty_value_display = "-пусто"


admin.site.register(Activity, ActivityAdmin)
admin.site.register(Ambassador, AmbassadorAdmin)
admin.site.register(AmbassadorActivity)
admin.site.register(AmbassadorPreference)
admin.site.register(Content)
admin.site.register(Content, ContentAdmin)
admin.site.register(MerchOnShipping)
admin.site.register(MerchShipment)
admin.site.register(Preference)
admin.site.register(Venue)
admin.site.register(MerchShipment, MerchShipmentAdmin)
admin.site.register(Merch, MerchAdmin)
admin.site.register(Venue, VenueAdmin)
1 change: 0 additions & 1 deletion crm_yandex/ambassadors/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,6 @@
]
CLOTHING_SIZE_MAX_LEN: int = 2
PROMOCODE_MAX_LEN: int = 20
PREFERENCE_MAX_LEN: int = 255
TELEGRAM_MAX_LEN: int = 32
SHIPMENT_STATUS_CHOICES = [
("unprocessed", "Необработанные"),
Expand Down
51 changes: 3 additions & 48 deletions crm_yandex/ambassadors/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,9 @@
from .constants import (AMBASSADOR_STATUS_CHOICES, CLOTHING_SIZE_CHOICES,
CLOTHING_SIZE_MAX_LEN, COURSE_CHOICES,
DECIMAL_MAX_DIGITS, DECIMAL_PLACES, GOAL_MAX_LEN,
NAME_MAX_LEN, PHONE_NUM_MAX_LEN, PREFERENCE_MAX_LEN,
PROMOCODE_MAX_LEN, SEX_CHOICES, SEX_MAX_LEN,
SHIPMENT_STATUS_CHOICES, STATUS_MAX_LEN,
TELEGRAM_MAX_LEN)
NAME_MAX_LEN, PHONE_NUM_MAX_LEN, PROMOCODE_MAX_LEN,
SEX_CHOICES, SEX_MAX_LEN, SHIPMENT_STATUS_CHOICES,
STATUS_MAX_LEN, TELEGRAM_MAX_LEN)
from .validators import POSTAL_CODE_VALIDATOR, TELEGRAM_USERNAME_VALIDATOR


Expand All @@ -26,21 +25,6 @@ def __str__(self):
return self.name


class Preference(models.Model):
name = models.CharField(
max_length=PREFERENCE_MAX_LEN,
verbose_name="Предпочтение"
)

class Meta:
verbose_name = "Предпочтение в рамкха амбассадорства"
verbose_name_plural = "Предпочтения в рамкха амбассадорства"
ordering = ["name"]

def __str__(self):
return self.name


class Ambassador(models.Model):
fio = models.CharField(
max_length=NAME_MAX_LEN,
Expand Down Expand Up @@ -135,13 +119,6 @@ class Ambassador(models.Model):
default="active",
verbose_name="Статус амбассадора"
)
preferences = models.ManyToManyField(
Preference,
through="AmbassadorPreference",
verbose_name="Предпочтения амбассадора",
related_name="ambassadors",
through_fields=("ambassador", "preference")
)
guide_one = models.BooleanField(
default=False,
verbose_name="Гайд 1"
Expand All @@ -164,28 +141,6 @@ def __str__(self):
return self.fio


class AmbassadorPreference(models.Model):
ambassador = models.ForeignKey(
Ambassador,
on_delete=models.CASCADE,
related_name="ambassador_preferences",
verbose_name="ID амбассадора"
)
preference = models.ForeignKey(
Preference,
on_delete=models.CASCADE,
related_name="ambassador_preferences",
verbose_name="ID предпочтения"
)

class Meta:
verbose_name = "Амбассадор-Предпочтение"
verbose_name_plural = "Амбассадор-Предпочтения"

def __str__(self):
return f"{self.ambassador} - {self.preference}"


class AmbassadorActivity(models.Model):
ambassador = models.ForeignKey(
Ambassador,
Expand Down
20 changes: 2 additions & 18 deletions crm_yandex/ambassadors/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,15 @@
from django.test import TestCase
from django.utils import timezone

from .models import (Activity, Ambassador, AmbassadorActivity,
AmbassadorPreference, Content, Merch, MerchOnShipping,
MerchShipment, Preference, Venue)
from .models import (Activity, Ambassador, AmbassadorActivity, Content, Merch,
MerchOnShipping, MerchShipment, Venue)
from .validators import POSTAL_CODE_VALIDATOR, TELEGRAM_USERNAME_VALIDATOR


class AmbassadorTests(TestCase):

def setUp(self):
self.activity = Activity.objects.create(name="Test_activity")
self.preference = Preference.objects.create(name="Test_preference")
self.ambassador = Ambassador.objects.create(
fio="Тест Тестов Тестович",
sex="М",
Expand Down Expand Up @@ -64,10 +62,6 @@ def setUp(self):
ambassador=self.ambassador,
activity=self.activity
)
self.ambassador_preference = AmbassadorPreference.objects.create(
ambassador=self.ambassador,
preference=self.preference
)
self.merch_on_shipping = MerchOnShipping.objects.create(
shipping=self.merch_shipment,
merch=self.merch,
Expand All @@ -78,9 +72,6 @@ def setUp(self):
def test_activity_listing(self):
self.assertEqual(self.activity.name, "Test_activity")

def test_preference_listing(self):
self.assertEqual(self.preference.name, "Test_preference")

def test_ambassador_listing(self):
self.assertEqual(self.ambassador.fio, "Тест Тестов Тестович")
self.assertEqual(self.ambassador.sex, "М")
Expand Down Expand Up @@ -130,7 +121,6 @@ def test_merch_shipment_listing(self):
def test_models_have_correct_object_names(self):
model_str = {
self.activity: self.activity.name,
self.preference: self.preference.name,
self.ambassador: self.ambassador.fio,
self.merch: f"{self.merch.merch_type} - {self.merch.cost}",
self.merch_shipment: (
Expand All @@ -150,12 +140,6 @@ def test_models_have_correct_object_names(self):
def test_relationships(self):
self.assertEqual(self.ambassador_activity.ambassador, self.ambassador)
self.assertEqual(self.ambassador_activity.activity, self.activity)
self.assertEqual(
self.ambassador_preference.ambassador, self.ambassador
)
self.assertEqual(
self.ambassador_preference.preference, self.preference
)
self.assertEqual(self.merch_on_shipping.shipping, self.merch_shipment)
self.assertEqual(self.merch_on_shipping.merch, self.merch)
self.assertEqual(self.merch_shipment.ambassador, self.ambassador)
Expand Down

0 comments on commit e3245e8

Please sign in to comment.