Skip to content

Commit

Permalink
Add position field to CommandKeyboardButton model
Browse files Browse the repository at this point in the history
  • Loading branch information
EXG1O committed Jun 5, 2024
1 parent 4df609d commit 2f919fd
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 6 deletions.
7 changes: 4 additions & 3 deletions telegram_bots/migrations/0001_initial.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Generated by Django 5.0.4 on 2024-05-10 22:27
# Generated by Django 5.0.6 on 2024-06-05 18:59

import django.db.models.deletion
import telegram_bots.models
Expand Down Expand Up @@ -147,7 +147,8 @@ class Migration(migrations.Migration):
name='CommandKeyboardButton',
fields=[
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('row', models.PositiveSmallIntegerField(blank=True, null=True, verbose_name='Ряд')),
('row', models.PositiveSmallIntegerField(verbose_name='Ряд')),
('position', models.PositiveSmallIntegerField(verbose_name='Позиция')),
('text', models.TextField(max_length=512, verbose_name='Текст')),
('url', models.URLField(blank=True, null=True, verbose_name='URL-адрес')),
('keyboard', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='buttons', to='telegram_bots.commandkeyboard', verbose_name='Клавиатура')),
Expand Down Expand Up @@ -222,7 +223,7 @@ class Migration(migrations.Migration):
fields=[
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('username', models.CharField(max_length=32, verbose_name='@username')),
('api_token', models.CharField(max_length=50, unique=True, validators=[telegram_bots.models.validate_api_token], verbose_name='API-токен')),
('api_token', models.CharField(error_messages={'unique': 'Telegram бот с таким API-токеном уже существует.'}, max_length=50, unique=True, validators=[telegram_bots.models.validate_api_token], verbose_name='API-токен')),
('storage_size', models.PositiveBigIntegerField(default=41943040, verbose_name='Размер хранилища')),
('is_private', models.BooleanField(default=False, verbose_name='Приватный')),
('is_enabled', models.BooleanField(default=False, verbose_name='Включён')),
Expand Down
3 changes: 2 additions & 1 deletion telegram_bots/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -344,7 +344,8 @@ class CommandKeyboardButton(models.Model):
related_name='buttons',
verbose_name=_('Клавиатура'),
)
row = models.PositiveSmallIntegerField(_('Ряд'), blank=True, null=True)
row = models.PositiveSmallIntegerField(_('Ряд'))
position = models.PositiveSmallIntegerField(_('Позиция'))
text = models.TextField(_('Текст'), max_length=512)
url = models.URLField(_('URL-адрес'), blank=True, null=True)
source_connections = GenericRelation(
Expand Down
5 changes: 3 additions & 2 deletions telegram_bots/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -270,7 +270,7 @@ class CommandKeyboardButtonSerializer(
):
class Meta:
model = CommandKeyboardButton
fields = ['id', 'row', 'text', 'url']
fields = ['id', 'row', 'position', 'text', 'url']


class CommandKeyboardSerializer(serializers.ModelSerializer[CommandKeyboard]):
Expand Down Expand Up @@ -500,6 +500,7 @@ def update(self, command: Command, validated_data: dict[str, Any]) -> Command:
id=button['id']
)
_button.row = button.get('row', _button.row)
_button.position = button.get('position', _button.position)
_button.text = button.get('text', _button.text)
_button.url = button.get('url', _button.url)

Expand Down Expand Up @@ -743,7 +744,7 @@ class DiagramCommandKeyboardButtonSerializer(

class Meta:
model = CommandKeyboardButton
fields = ['id', 'row', 'text', 'url', 'source_connections']
fields = ['id', 'row', 'position', 'text', 'url', 'source_connections']


class DiagramCommandKeyboardSerializer(serializers.ModelSerializer[CommandKeyboard]):
Expand Down

0 comments on commit 2f919fd

Please sign in to comment.