Hi guys,
Apologies in advance for what I know is a confusing question.
I am upgrading a site to django 3 but the old version didn't use URLs the canonical way (it didn't use slugs or indexes, it was hard coded).
I'm trying to do it properly and of course half of it is broken :/
Summary: I want to have two different class-based views that do different things each over instances of the same model.
I have one Model called "Tool" and two class-based views: ToolView and AdvancedToolView that do different things with instances of that model
- Tool is a model that contains a bunch of text.
- ToolView is a generic view that only implements GET and displays model instances based on parameter tool_name. It works.
- AdvancedToolView is a subclass of ToolView that implements POST. It used to work with my hardcoded urls, but now I can't resolve it.
My urls.py
urlpatterns += [
path(
"section/<str:section_name>/advanced-tool/",
views.AdvancedToolView.as_view(tool_name="Advanced Tool"), #this is not resolving
name="Advanced_tool",
),
# this works
path("section/<str:section_name>/<slug:slug>/", views.ToolView.as_view(), name="tools"),
]
The idea is: .../advanced-tool/ goes to view AdvancedToolView, any other slug goes to ToolView.
I think at least one problem is that I override get_absolute_url in model.Tool:
class Tool(models.Model):
name = models.CharField(...)
slug = models.SlugField(...) # slug is the slugyfied version of name
payload = ...
def get_absolute_url(self):
return reverse("shed:tools", kwargs={"section_name": Section.objects.filter(...), "tool_name": self.slug})
On my site, these work:
/shed/section/Main/current-problems/
/shed/section/Main/order-summary/
But this one errors with "No Tool matches the given query." -- /shed/section/Main/advanced-tool/
What is the correct way to dispatch /advanced-tool/ to view.AdvancedToolView ???
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/c80d23f0-4af2-4ed2-8e7c-c155503f93b2%40googlegroups.com.
No comments:
Post a Comment