carltongibson / neapolitan

Quick CRUD views for Django
https://noumenal.es/neapolitan/
MIT License
516 stars 36 forks source link

List view had no options to change or create #68

Closed mfoulds closed 23 hours ago

mfoulds commented 23 hours ago

Hi

I followed the tutorial, but when navigating to the list view, I cannot see the expected View | Edit | Delete options or any button to create a new record.

I added the new model, view and addition to urlpatterns in an existing app called fstp. Registered the model with admin and added some records via the admin panel.

# fstp/models.py - just showing the model
class Project(models.Model):
    name = models.CharField(max_length=200)
    owner = models.CharField(max_length=200)
    has_tests = models.BooleanField()
    has_docs = models.BooleanField()

    NA = "na"
    PLANNED = "PL"
    STARTED = "ST"
    FIRST_RESULTS = "FR"
    MATURE_RESULTS = "MR"
    DONE = "DO"
    DEFERRED = "DE"
    BLOCKED = "BL"
    INACTIVE = "IN"

    STATUS_CHOICES = [
        (PLANNED, "Planned"),
        (STARTED, "Started"),
        (FIRST_RESULTS, "First results"),
        (MATURE_RESULTS, "Mature results"),
        (DONE, "Done"),
        (DEFERRED, "Deferred"),
        (BLOCKED, "Blocked"),
        (INACTIVE, "Inactive"),
    ]

    status = models.CharField(
        max_length=2,
        choices=STATUS_CHOICES,
    )

    last_review = models.DateField(null=True, blank=True)

    def is_at_risk(self):
        return self.status in {self.BLOCKED, self.INACTIVE}

    def __str__(self):
        return self.name
# fstp/views.py
class ProjectView(CRUDView):
    model = models.Project
    fields = ["name", "owner", "last_review", "has_tests", "has_docs", "status"]
fstp/urls.py
urlpatterns = [
    path("test-import/", views.test_import_view, name="test_import"),
]

urlpatterns += views.ProjectView.get_urls()

Project's urls.py has: path("fstp/", include("apps.fstp.urls", namespace="fstp")),

I also created the expected base.html in my projects templates/neapolitan/base.html:

<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>{% block title %}Ice Cream Dream{% endblock %}</title>
    <script src="https://code.jquery.com/jquery-3.7.1.min.js"
        integrity="sha256-/JqT3SQfawRcv/BIHPThkBvs0OEvtFFmqPF/lYI/Cxo=" crossorigin="anonymous"></script>
    <script src="https://cdn.tailwindcss.com"></script>
    {% block head %}{% endblock %}
</head>

<body class="flex items-center justify-center h-screen">
    <div class="max-w-3xl w-full">
        {% block content %}{% endblock %}
    </div>
</body>

</html>

When I navigate to localhost:8000/fstp/project/ I just see the table data image

carltongibson commented 23 hours ago

Neapolitan's reversing doesn't currently work with namespaced URLs. See #16.

If you move the urlpatterns += views.ProjectView.get_urls() to you main URLs file you get the result you're looking for, except without the include prefix, with you can set by providing .url_base on your CRUDView subclass.

carltongibson commented 23 hours ago

I'm going to close as a duplicate.