Skip to content

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also .

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also .
  • 3 commits
  • 3 files changed
  • 0 commit comments
  • 1 contributor
View
38 armstrong/apps/related_content/admin.py
@@ -79,29 +79,31 @@ def formfield_for_foreignkey_helper(inline, *args, **kwargs):
def related_content_inline_factory(allowed_types=None, allowed_content_types=None):
- #custom_widgets = RelatedContentInlineForm.Meta.widgets.copy()
- #custom_widgets.update({
- # "related_type": django_widgets.HiddenInput(),
- # })
-
+ related_type_kwargs = {
+ "label": "Related Type"
+ }
if allowed_types is None:
- type_qs = RelatedType.objects.all()
+ related_type_kwargs['queryset'] = RelatedType.objects.all()
else:
- type_qs = RelatedType.objects.filter(title__in=allowed_types)
-
- if allowed_content_types is None:
- content_type_qs = ContentType.objects.all()
+ related_type_kwargs['queryset'] = RelatedType.objects.filter(title__in=allowed_types)
+ if len(related_type_kwargs['queryset']) == 1:
+ related_type_kwargs['initial'] = related_type_kwargs['queryset'][0]
+ related_type_kwargs['widget'] = django_widgets.HiddenInput()
+
+ destination_type_kwargs = {
+ "label": "Destination Type"
+ }
+ if allowed_types is None:
+ destination_type_kwargs['queryset'] = ContentType.objects.all()
else:
- content_type_qs = ContentType.objects.filter(name__in=allowed_content_types)
-
+ destination_type_kwargs['queryset'] = ContentType.objects.filter(name__in=allowed_content_types)
+ if len(destination_type_kwargs['queryset']) == 1:
+ destination_type_kwargs['initial'] = destination_type_kwargs['queryset'][0]
+ destination_type_kwargs['widget'] = django_widgets.HiddenInput()
class CustomRelatedContentInlineForm(RelatedContentInlineForm):
- related_type = forms.ModelChoiceField(label="Related Type",
- queryset=type_qs)
- destination_type = forms.ModelChoiceField(label="Destination Type",
- queryset=content_type_qs)
- #class Meta(RelatedContentInlineForm.Meta):
- #widgets = custom_widgets
+ related_type = forms.ModelChoiceField(**related_type_kwargs)
+ destination_type = forms.ModelChoiceField(**destination_type_kwargs)
class CustomRelatedContentInline(RelatedContentInline):
form = CustomRelatedContentInlineForm
View
7 armstrong/apps/related_content/static/admin/related_content/related_content_inline.js
@@ -1,7 +0,0 @@
-(function($){
- $(document).ready(function(){
- $('.inline-related .add-row a').click(function(){
- alert('maybe?');
- });
- });
-})(django.jQuery);
View
33 armstrong/apps/related_content/templates/admin/edit_inline/related_content.html
@@ -7,9 +7,10 @@
{{ inline_admin_formset.formset.non_form_errors }}
<table>
<thead><tr>
+ <th></th>
{% for field in inline_admin_formset.fields %}
{% if not field.widget.is_hidden %}
- <th{% if forloop.first %} colspan="2"{% endif %}{% if field.required %} class="required"{% endif %}>{{ field.label|capfirst }}</th>
+ <th{% if field.required %} class="required"{% endif %}>{{ field.label|capfirst }}</th>
{% endif %}
{% endfor %}
{% if inline_admin_formset.formset.can_delete %}<th>{% trans "Delete?" %}</th>{% endif %}
@@ -30,30 +31,18 @@
{% if inline_admin_form.has_auto_field %}{{ inline_admin_form.pk_field.field }}{% endif %}
{{ inline_admin_form.fk_field.field }}
{% spaceless %}
- {% for fieldset in inline_admin_form %}
- {% for line in fieldset %}
- {% for field in line %}
- {% if field.field.is_hidden %} {{ field.field }} {% endif %}
- {% endfor %}
- {% endfor %}
+ {% for field in inline_admin_form.form.hidden_fields %}
+ {{ field }}
{% endfor %}
{% endspaceless %}
</td>
- {% for fieldset in inline_admin_form %}
- {% for line in fieldset %}
- {% for field in line %}
- {% if not field.field.is_hidden %}
- <td class="{{ field.field.name }}">
- {% if field.is_readonly %}
- <p>{{ field.contents }}</p>
- {% else %}
- {{ field.field.errors.as_ul }}
- {{ field.field }}
- {% endif %}
- </td>
- {% endif %}
- {% endfor %}
- {% endfor %}
+ {% for field in inline_admin_form.form.visible_fields %}
+ {% if not field.name == 'DELETE' %}
+ <td class="{{ field.name }}">
+ {{ field.errors.as_ul }}
+ {{ field }}
+ </td>
+ {% endif %}
{% endfor %}
{% if inline_admin_formset.formset.can_delete %}
<td class="delete">{% if inline_admin_form.original %}{{ inline_admin_form.deletion_field.field }}{% endif %}</td>

No commit comments for this range

Something went wrong with that request. Please try again.