new: add support for optional link label

This commit is contained in:
Matthew Ryan Dillon 2022-01-10 16:04:30 -07:00
parent 93fe4a1a5b
commit 005d343020
6 changed files with 44 additions and 4 deletions

View file

@ -8,13 +8,16 @@ from .models import Link
class LinkForm(forms.ModelForm):
class Meta:
model = Link
fields = ['url', 'sets']
fields = ['url', 'label', 'sets']
label = forms.CharField(widget=forms.HiddenInput, required=False)
url = forms.CharField(label='', widget=forms.TextInput(attrs={'autofocus': True}))
sets = forms.CharField(widget=forms.HiddenInput, required=False)
class LinkEditForm(LinkForm):
label = forms.CharField(label='label')
sets = forms.ModelMultipleChoiceField(
label='sets',
queryset=Set.objects.filter(done=False).order_by('-updated_at'),

View file

@ -0,0 +1,18 @@
# Generated by Django 4.0 on 2022-01-10 22:58
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('links', '0002_initial'),
]
operations = [
migrations.AddField(
model_name='link',
name='label',
field=models.CharField(blank=True, max_length=500, verbose_name='Label'),
),
]

View file

@ -9,6 +9,7 @@ _salts = settings.DJANGO_HASHID_SALTS
class Link(models.Model):
slug = HashidsField(real_field_name='id', salt=_salts['link'])
url = models.URLField(verbose_name='URL')
label = models.CharField(max_length=500, blank=True, verbose_name='Label')
sets = models.ManyToManyField('sets.Set', through='sets.SetLink', related_name='sets')
done = models.BooleanField(default=False, verbose_name='Done?')
created_at = models.DateTimeField(auto_now_add=True, verbose_name='Created At')

View file

@ -17,7 +17,13 @@
<tbody>
{% for link in links %}
<tr>
<td><a href="{{ link.url }}" target="_blank">{{ link.url }}</a></td>
<td><a href="{{ link.url }}" target="_blank">
{% if link.label %}
{{ link.label }}
{% else %}
{{ link.url }}
{% endif %}
</a></td>
<td class="fit">
<a href="{% url 'links:detail' link.slug %}">
<code>{{ link.slug }}</code>

View file

@ -18,7 +18,13 @@
<tbody>
{% for link in links %}
<tr>
<td><a href="{{ link.url }}" target="_blank">{{ link.url }}</a></td>
<td><a href="{{ link.url }}" target="_blank">
{% if link.label %}
{{ link.label }}
{% else %}
{{ link.url }}
{% endif %}
</a></td>
<td class="fit">
<a href="{% url 'links:detail' link.slug %}">
<code>{{ link.slug }}</code>

View file

@ -5,7 +5,13 @@
<tbody>
{% for link in links %}
<tr>
<td><a href="{{ link.url }}">{{ link.url }}</a></td>
<td><a href="{{ link.url }}">
{% if link.label %}
{{ link.label }}
{% else %}
{{ link.url }}
{% endif %}
</a></td>
<td class="fit"><code>{{ link.slug }}</code></td>
</tr>
{% empty %}