Hi, I'm new on Django.
I'm trying to develop a site that will have several Django-app.
I would like to define an unique name for slug in each model (for example 
airslug defined as SlugField in my aircraftt model). I use a ListView that 
call a DetailView and I need the slug to have the right URL. 

If I use the field name slug in Model, View, Url 
*everything is working fine*
If instead I use a field name airslug *noway to make it run*!!! I tried 
several way but without results...

Could someone help me? Thanks in advance to all of you.

*URL *
from django.contrib import admin
from django.urls import include, path

urlpatterns = [
    path('', include('base.urls')),
    path('aircraftapp/', include('aircraftapp.urls')),
    path('admin/', admin.site.urls),

*URL app:*
from django.urls import path

from aircraftapp.views import AircraftListView
from aircraftapp.views import AircraftDetailView

urlpatterns = [
    path('', AircraftListView.as_view(), name='aircraft_list'),
    path('<slug:slug>/', AircraftDetailView.as_view(), name='aircraft_detail'),

*Model:*
slug = models.SlugField(max_length=50, allow_unicode=True, blank=True)


    def __str__(self):
        return self.air_tailnumber

    def get_absolute_url(self):
        return reverse('aircraft_detail', kwargs={'slug': self.slug})

View:
# aircraftapp views :
# List view
class AircraftListView(ListView):

    model = Aircraft

    def get_context_data(self, **kwargs):
        context = super().get_context_data(**kwargs)
        return context 

# Details View
class AircraftDetailView(DetailView):

    model = Aircraft

    def get_context_data(self, **kwargs):
        context = super().get_context_data(**kwargs)
        return context

*DetailView Template: (basic jut for test)*
{% extends 'base/base.html' %}
{% load static %}
{% block content %}

<h1>Aircraft Details</h1>
<h1>{{ object.air_tailnumber }}</h1>

<p>{{ object.air_description }}</p>
<p>{{ object.air_creator }}</p>
<p>{{ object.air_creationdate }}</p>
<p>{{ object.air_modifier }}</p>
<p>{{ object.air_modified }}</p>
<p>{{ object.slug }}</p>

{% endblock content %}

-- 
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+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/c7f75913-14b7-4c20-b558-c393623cb89bn%40googlegroups.com.

Reply via email to