add Position.short_name
This commit is contained in:
parent
ec61155833
commit
fb29533a60
3 changed files with 33 additions and 1 deletions
31
src/c3nav/mapdata/migrations/0137_position_short_name.py
Normal file
31
src/c3nav/mapdata/migrations/0137_position_short_name.py
Normal file
|
@ -0,0 +1,31 @@
|
||||||
|
# Generated by Django 5.0.8 on 2024-12-29 16:38
|
||||||
|
|
||||||
|
from django.db import migrations, models
|
||||||
|
|
||||||
|
|
||||||
|
def generate_short_name(apps, schema_editor):
|
||||||
|
Position = apps.get_model('mapdata', 'position')
|
||||||
|
for position in Position.objects.all():
|
||||||
|
position.short_name = position.name[:2]
|
||||||
|
position.save()
|
||||||
|
|
||||||
|
|
||||||
|
class Migration(migrations.Migration):
|
||||||
|
|
||||||
|
dependencies = [
|
||||||
|
('mapdata', '0136_wifi_bssids_to_addresses_and_more'),
|
||||||
|
]
|
||||||
|
|
||||||
|
operations = [
|
||||||
|
migrations.AddField(
|
||||||
|
model_name='position',
|
||||||
|
name='short_name',
|
||||||
|
field=models.CharField(help_text='two characters maximum', max_length=2, null=True, verbose_name='abbreviation'),
|
||||||
|
),
|
||||||
|
migrations.RunPython(generate_short_name, migrations.RunPython.noop),
|
||||||
|
migrations.AlterField(
|
||||||
|
model_name='position',
|
||||||
|
name='short_name',
|
||||||
|
field=models.CharField(help_text='two characters maximum', max_length=2, verbose_name='abbreviation'),
|
||||||
|
),
|
||||||
|
]
|
|
@ -587,6 +587,7 @@ class Position(CustomLocationProxyMixin, models.Model):
|
||||||
|
|
||||||
owner = models.ForeignKey(settings.AUTH_USER_MODEL, on_delete=models.CASCADE)
|
owner = models.ForeignKey(settings.AUTH_USER_MODEL, on_delete=models.CASCADE)
|
||||||
name = models.CharField(_('name'), max_length=32)
|
name = models.CharField(_('name'), max_length=32)
|
||||||
|
short_name = models.CharField(_('abbreviation'), help_text=_('two characters maximum'), max_length=2)
|
||||||
secret = models.CharField(_('secret'), unique=True, max_length=32, default=get_position_secret)
|
secret = models.CharField(_('secret'), unique=True, max_length=32, default=get_position_secret)
|
||||||
last_coordinates_update = models.DateTimeField(_('last coordinates update'), null=True)
|
last_coordinates_update = models.DateTimeField(_('last coordinates update'), null=True)
|
||||||
timeout = models.PositiveSmallIntegerField(_('timeout (in seconds)'), default=0, blank=True,
|
timeout = models.PositiveSmallIntegerField(_('timeout (in seconds)'), default=0, blank=True,
|
||||||
|
|
|
@ -80,7 +80,7 @@ class ReportUpdateForm(ModelForm):
|
||||||
class PositionForm(ModelForm):
|
class PositionForm(ModelForm):
|
||||||
class Meta:
|
class Meta:
|
||||||
model = Position
|
model = Position
|
||||||
fields = ['name', 'timeout']
|
fields = ['name' ,"short_name", 'timeout']
|
||||||
|
|
||||||
|
|
||||||
class PositionSetForm(Form):
|
class PositionSetForm(Form):
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue