carltongibson / neapolitan

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

'model-create' is not a valid view function or pattern name #51

Closed tantalusblank closed 1 week ago

tantalusblank commented 1 week ago

I'm currently trying to implement Neapolitan into my Django project for the first time and getting the error as per the title.

First Some Detail

class AssetView(CRUDView): model = Asset fields = ["asset_type", "asset_number"]

- And added in to `urls.py`:

urlpatterns += views.AssetView.get_urls()

### The Problem
Unfortunately when I do this and try to navigate to `http://127.0.0.1:8000/engineeringinterface/asset/`, I get the following:

Request URL: http://127.0.0.1:8000/engineeringinterface/asset/ Django Version: 5.0.6 Exception Type: NoReverseMatch Exception Value: Reverse for 'asset-create' not found. 'asset-create' is not a valid view function or pattern name.


I'm relatively new to Django, so there may be some convention I'm not following properly.

### Suspect Causes

1. The folder structure could be unconventional, and maybe I need to specifically define a path somewhere
Current structure is:

projectroot | manage.py | src | myapp | settings.py | urls.py | engineeringinterface | models.py | views.py | urls.py | templates | engineeringinterface | base.html


(some files and folders omitted, but mainly to show ones of significance)

2. Another installed app or middleware causing an issue (e.g. django-simple-history)
carltongibson commented 1 week ago

@tantalusblank That looks OK. Can you give me a running example?

tantalusblank commented 1 week ago

Thanks for the speedy reply @carltongibson, though sorry could you clarify what you mean by a running example?

carltongibson commented 1 week ago

Like a test case or example project that shows the issue. (There's something you didn't tell me, but I don't know what.)

carltongibson commented 1 week ago

@tantalusblank Give v24.5 a go, which I just released, that fixes a maybe related issue.

If that doesn't solve it then you'll need to give me an example project to look at.

tantalusblank commented 1 week ago

Thanks I'll give 24.5 a go on Monday - really appreciate the support. If that doesn't work I'll try and share as much of the project as possible

carltongibson commented 1 week ago

Great. Thanks.

I'd suggest starting with a fresh project , then try to reproduce the issue with the absolute minimum you need to add. That will show exactly where the issue is.

tantalusblank commented 1 week ago

While 24.5 did seem to solve the problem I was having, it then couldn't find base.html (until I duplicated it into the templates root), and now it is displaying the table! However, although it could be a CSS issue, I can't see any options to create/modify/delete any records.

You should have an invite to a project that is a stripped down version of the app.

carltongibson commented 1 week ago

app_name = "engineeringinterface"

Neapolitan's view name generation is not compatible with url namespaces. Either don't use one, or move your CRUDView URLs into your main URLConf.

carltongibson commented 1 week ago

Duplicate of #16 really

tantalusblank commented 1 week ago

Removed the namespace and everything seems to work fine - thanks @carltongibson

carltongibson commented 1 week ago

Great. Thanks for the follow up!