mirror of
https://github.com/wahyd4/links.git
synced 2026-08-08 21:04:53 +10:00
Make editing custom link work
This commit is contained in:
@@ -24,6 +24,7 @@ urlpatterns = [
|
||||
path('link/<int:pk>/', LinkDetailView.as_view(), name='link_detail'),
|
||||
path('link/<int:pk>/edit/', LinkUpdateView.as_view(), name='link_update'),
|
||||
path('custom/<slug:alias>/', CustomLinkView.as_view(), name='custom_link'),
|
||||
path('custom/<slug:alias>/edit/', LinkUpdateView.as_view(), name='custom_link_update'),
|
||||
|
||||
# Include main app URLs with locale
|
||||
path('', include('links.urls')),
|
||||
|
||||
Binary file not shown.
@@ -133,6 +133,22 @@ class LinkUpdateView(UpdateView):
|
||||
form_class = LinkForm
|
||||
template_name = 'links/link_form.html'
|
||||
|
||||
def get_object(self, queryset=None):
|
||||
# Handle both pk (for regular links) and alias (for custom links)
|
||||
pk = self.kwargs.get('pk')
|
||||
alias = self.kwargs.get('alias')
|
||||
|
||||
if pk:
|
||||
# Regular link lookup by pk
|
||||
return get_object_or_404(Link, pk=pk)
|
||||
elif alias:
|
||||
# Custom link lookup by alias
|
||||
alias = alias.lower()
|
||||
return get_object_or_404(Link, alias=alias, link_type=Link.LinkType.CUSTOM)
|
||||
else:
|
||||
# Fallback to default behavior
|
||||
return super().get_object(queryset)
|
||||
|
||||
def get_initial(self):
|
||||
initial = super().get_initial()
|
||||
self.original_url = self.object.original_url
|
||||
|
||||
Reference in New Issue
Block a user