-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Create generic Create, View, Update, Delete and List views that work with ContentTypes
- Loading branch information
Showing
7 changed files
with
130 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
{% extends basetemplate|default:"base.html" %} | ||
|
||
{% block content %} | ||
<div class="modal-dialog"> | ||
<div class="modal-content"> | ||
<div class="modal-header"> | ||
<h3 class="modal-title">Confirm delete</h3> | ||
<button type="button" class="close" data-dismiss="modal">×</button> | ||
</div> | ||
<div class="modal-body"> | ||
<form action="" method="post"> | ||
{% csrf_token %} | ||
<h4> | ||
Are you sure you want to delete: <strong>{{ object }}</strong> ? | ||
</h4> | ||
<input class="btn btn-danger" type="submit" value="Yes, I want to delete" /> | ||
</form> | ||
</div> | ||
<div class="modal-footer"> | ||
<input class="btn" | ||
type="submit" | ||
value="No, bring me back" | ||
onclick="goBack()" /> | ||
</div> | ||
</div> | ||
</div> | ||
<script> | ||
function goBack() { | ||
window.history.back(); | ||
} | ||
</script> | ||
{% endblock content %} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
{% extends basetemplate|default:"base.html" %} | ||
{% load render_table from django_tables2 %} | ||
|
||
{% block content %} | ||
{{ object }} | ||
{% endblock content %} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
{% extends basetemplate|default:"base.html" %} | ||
{% load crispy_forms_tags %} | ||
|
||
{% block content %} | ||
{% crispy form %} | ||
{% endblock content %} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
{% extends basetemplate|default:"base.html" %} | ||
{% load render_table from django_tables2 %} | ||
|
||
{% block content %} | ||
{% render_table table %} | ||
{% endblock content %} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
from django.contrib.contenttypes.models import ContentType | ||
from django.shortcuts import get_object_or_404 | ||
from django.urls import include, path, register_converter | ||
|
||
from apis_core.core import views | ||
|
||
|
||
class ContenttypeConverter: | ||
regex = r"\w+\.\w+" | ||
|
||
def to_python(self, value): | ||
app_label, model = value.split(".") | ||
return get_object_or_404(ContentType, app_label=app_label, model=model) | ||
|
||
def to_url(self, value): | ||
return f"{value.app_label}.{value.model}" | ||
|
||
|
||
register_converter(ContenttypeConverter, "ccc") | ||
|
||
app_name = "core" | ||
|
||
urlpatterns = [ | ||
path( | ||
"<ccc:contenttype>/", | ||
include( | ||
[ | ||
path("", views.ListCC.as_view(), name="genericlist"), | ||
path("<int:pk>", views.DetailCC.as_view()), | ||
path("create", views.CreateCC.as_view()), | ||
path("delete/<int:pk>", views.DeleteCC.as_view()), | ||
path("update/<int:pk>", views.UpdateCC.as_view()), | ||
] | ||
), | ||
) | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters