Skip to content

Commit

Permalink
Fix CloudHost Tabular Inline (#3871)
Browse files Browse the repository at this point in the history
* Fix CloudHostTabularInline

* Cleanup
  • Loading branch information
matyldv authored Dec 11, 2024
1 parent 74f660e commit 3839c45
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/ralph/admin/templates/admin/edit_inline/tabular.html
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ <h2>{{ inline_admin_formset.opts.verbose_name_plural|capfirst }}</h2>
</td>
</tr>
{% endif %}
<tr class="form-row {% cycle "row1" "row2" %} {% if inline_admin_form.original or inline_admin_form.show_url %}has_original{% endif %}{% if forloop.last %} empty-form{% endif %}" id="{{ inline_admin_formset.formset.prefix }}-{% if not forloop.last %}{{ forloop.counter0 }}{% else %}empty{% endif %}">
<tr class="form-row {% cycle "row1" "row2" %} {% if inline_admin_form.original or inline_admin_form.show_url %}has_original{% endif %}{% if forloop.last and inline_admin_formset.has_add_permission %} empty-form{% endif %}" id="{{ inline_admin_formset.formset.prefix }}-{% if not forloop.last %}{{ forloop.counter0 }}{% else %}empty{% endif %}">
{% for fieldset in inline_admin_form %}
{% for line in fieldset %}
{% for field in line %}
Expand Down
7 changes: 7 additions & 0 deletions src/ralph/virtual/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
from django.contrib.contenttypes.models import ContentType
from django.core.exceptions import ValidationError
from django.db.models import Count, Prefetch
from django.forms import BaseInlineFormSet
from django.urls import reverse
from django.utils.safestring import mark_safe
from django.utils.translation import ugettext_lazy as _
Expand Down Expand Up @@ -184,13 +185,19 @@ def parent_(self, obj):
return '-'


class CloudHostInlineFormset(BaseInlineFormSet):
def get_queryset(self):
return super().get_queryset()[:]


class CloudHostTabularInline(RalphTabularInline):
can_delete = False
model = CloudHost
fk_name = 'parent'
fields = ['get_hostname', 'get_hypervisor', 'get_ip_addresses', 'created',
'tags', 'remarks']
readonly_fields = fields
formset = CloudHostInlineFormset

@mark_safe
def get_hostname(self, obj):
Expand Down

0 comments on commit 3839c45

Please sign in to comment.