Skip to content

Commit c1eec1c

Browse files
committed
my testapp making use of the frontend part of django-filer
my testapp making use of the frontend part of django-filer
1 parent 819bece commit c1eec1c

File tree

6 files changed

+64
-9
lines changed

6 files changed

+64
-9
lines changed

testapp/migrations/0001_initial.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
# Generated by Django 4.2.15 on 2024-10-26 08:46
2+
3+
from django.db import migrations, models
4+
import finder.models.fields
5+
6+
7+
class Migration(migrations.Migration):
8+
9+
initial = True
10+
11+
dependencies = [
12+
]
13+
14+
operations = [
15+
migrations.CreateModel(
16+
name='TestAppModel',
17+
fields=[
18+
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
19+
('file', finder.models.fields.FinderFileField(blank=True, null=True, verbose_name='Demo File')),
20+
],
21+
),
22+
]

testapp/migrations/__init__.py

Whitespace-only changes.

testapp/models.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
from django.db import models
2+
3+
from finder.models.fields import FinderFileField
4+
5+
6+
class TestAppModel(models.Model):
7+
file = FinderFileField(
8+
verbose_name="Demo File",
9+
null=True,
10+
blank=True,
11+
)

testapp/templates/testapp.html

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,17 +8,22 @@
88
<title>Django-Filer</title>
99
<link rel="icon" href="data:,">
1010
<link href="{% static 'node_modules/bootstrap/dist/css/bootstrap.min.css' %}" rel="stylesheet">
11-
<link href="{% static 'finder/css/finder-browser.css' %}" rel="stylesheet">
1211
<script src="{% url 'finder-api:javascript-catalog' %}"></script>
13-
<script type="module" src="{% static 'finder/js/finder-browser.js' %}"></script>
12+
{{ form.media }}
1413
</head>
1514

1615
<body>
1716
<div class="container">
1817
<div class="row">
1918
<div class="col mx-auto my-5">
2019
<h1>Django Filer Demo</h1>
21-
<finder-file-select base-url="{% url 'finder-api:base-url' %}" realm="admin" csrf-token="{{ csrf_token }}"></finder-file-select>
20+
<form method="post">
21+
{% csrf_token %}
22+
{{ form }}
23+
<p>
24+
<button type="submit" class="btn btn-primary">Submit</button>
25+
</p>
26+
</form>
2227
</div>
2328
</div>
2429
</div>

testapp/urls.py

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,21 +16,17 @@
1616
from django.conf import settings
1717
from django.conf.urls.static import static
1818
from django.contrib import admin
19-
from django.shortcuts import render
2019
from django.urls import include, path
2120

2221
from finder.api import urls as finder_urls
2322

24-
25-
def render_landing(request):
26-
context = {}
27-
return render(request, 'testapp.html', context)
23+
from testapp.views import TestAppView
2824

2925

3026
urlpatterns = [
3127
path('admin/', admin.site.urls),
3228
path('finder-api/', include(finder_urls)),
33-
path('testapp/', render_landing),
29+
path('testapp/', TestAppView.as_view(), name='testapp'),
3430
]
3531
if settings.DEBUG:
3632
urlpatterns.extend(static(

testapp/views.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
from django.views.generic.edit import UpdateView
2+
3+
from testapp.models import TestAppModel
4+
5+
6+
class TestAppView(UpdateView):
7+
model = TestAppModel
8+
fields = '__all__'
9+
template_name = 'testapp.html'
10+
11+
def get_object(self, queryset=None):
12+
if obj := TestAppModel.objects.first():
13+
return obj
14+
return TestAppModel.objects.create()
15+
16+
def get_success_url(self):
17+
return self.request.path
18+
19+
def get_context_data(self, **kwargs):
20+
context = super().get_context_data(**kwargs)
21+
return context

0 commit comments

Comments
 (0)