-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
57 additions
and
4 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 @@ | ||
from . import fields, widgets # noqa |
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,7 @@ | ||
from django import forms | ||
|
||
from .widgets import ClearableBlobInput | ||
|
||
|
||
class BlobField(forms.FileField): | ||
widget = ClearableBlobInput |
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,10 @@ | ||
from django.forms.widgets import ClearableFileInput | ||
|
||
|
||
class ClearableBlobInput(ClearableFileInput): | ||
# make this widget work with the Django admin | ||
choices = [] | ||
|
||
|
||
class AdminBlobInput(ClearableBlobInput): | ||
template_name = "anchor/widgets/admin_blob_input.html" |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
{% load anchor %} | ||
<div style="display: flex; flex-wrap: wrap; gap: 0.5rem"> | ||
<div> | ||
{% if widget.is_initial %} | ||
{% if widget.value.is_image %} | ||
<img style="max-width: 200px; max-height: 200px; object-fit: contain;" | ||
src="{% variant_url widget.value resize_to_fit='200x200' %}"> | ||
{% else %} | ||
{{ widget.initial_text }}: <a href="{{ widget.value.url }}">{{ widget.value }}</a> | ||
{% endif %} | ||
{% endif %} | ||
</div> | ||
<div> | ||
{% if not widget.required and widget.is_initial %} | ||
<div> | ||
<div style="display: flex; align-items: center; gap: 0.25em"> | ||
<input type="checkbox" {% if widget.attrs.disabled %} disabled{% endif %} | ||
name="{{ widget.checkbox_name }}" id="{{ widget.checkbox_id }}"> | ||
<label for="{{ widget.checkbox_id }}">{{ widget.clear_checkbox_label }}</label> | ||
</div> | ||
</div> | ||
{% endif %} | ||
<input type="{{ widget.type }}" name="{{ widget.name }}" {% include "django/forms/widgets/attrs.html" %}> | ||
</div> | ||
</div> |
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 |
---|---|---|
@@ -1,9 +1,18 @@ | ||
from django.contrib import admin | ||
|
||
from anchor.forms.widgets import AdminBlobInput | ||
from anchor.models.fields import SingleAttachmentField | ||
|
||
from .models import Movie | ||
|
||
|
||
@admin.register(Movie) | ||
class MovieAdmin(admin.ModelAdmin): | ||
list_display = ["title"] | ||
search_fields = ["title"] | ||
|
||
formfield_overrides = { | ||
SingleAttachmentField: { | ||
"widget": AdminBlobInput, | ||
}, | ||
} |