- Add birth_date, created_at/updated_at to Employee; remove username field - Introduce EmployeeAction for tracking HR events and is_actually_active/status properties - Create BotSubscriber model (OneToOne relation) for TG/WA binding - Implement Aiogram-based Telegram bot: • request contact to bind by phone or @username • department selection keyboard from DEPARTMENTS dict • async ORM via sync_to_async, custom filters for bound & active employees - Update profile view & template: • show “Bind Telegram/WhatsApp” button only when not already bound • preview avatar on upload - Remove registration tokens in favor of contact-based auth - Clean up templates, forms and add avatar validation mixin
33 lines
805 B
Python
33 lines
805 B
Python
# bots/models.py
|
|
import uuid
|
|
from django.db import models
|
|
from django.contrib.auth import get_user_model
|
|
|
|
User = get_user_model()
|
|
|
|
|
|
class BotSubscriber(models.Model):
|
|
user = models.OneToOneField(
|
|
User,
|
|
on_delete=models.CASCADE,
|
|
related_name='bot_subscription'
|
|
)
|
|
telegram_id = models.BigIntegerField(
|
|
'Telegram ID',
|
|
null=True, blank=True,
|
|
unique=True
|
|
)
|
|
whatsapp_id = models.CharField(
|
|
'WhatsApp ID',
|
|
max_length=64,
|
|
null=True, blank=True,
|
|
unique=True
|
|
)
|
|
|
|
class Meta:
|
|
verbose_name = 'Подписчик бота'
|
|
verbose_name_plural = 'Подписчики ботов'
|
|
|
|
def __str__(self):
|
|
return f'{self.user} (TG={self.telegram_id or "-"} / WA={self.whatsapp_id or "-"})'
|