[Django] #34651: 'list' object has no attribute '_committed'

7 views
Skip to first unread message

Django

unread,
Jun 13, 2023, 8:14:07 AM6/13/23
to django-...@googlegroups.com
#34651: 'list' object has no attribute '_committed'
------------------------------------------------+------------------------
Reporter: viniciustahech | Owner: nobody
Type: Cleanup/optimization | Status: new
Component: Uncategorized | Version: 4.2
Severity: Normal | Keywords:
Triage Stage: Unreviewed | Has patch: 0
Needs documentation: 0 | Needs tests: 0
Patch needs improvement: 0 | Easy pickings: 0
UI/UX: 0 |
------------------------------------------------+------------------------
I'm trying to work with multiple files without success. I'm working on the
implementation in the admin, and then on to the form.

For a single file it works fine

from .models import ServiceOrder, MaintenanceService
from django.contrib import admin
from django.forms import Textarea


# Register your models here.
@admin.register(ServiceOrder)
class OrderServiceAdmin(admin.ModelAdmin):

list_display = ('id', 'requester', 'due_date', 'service_type',
'notes', 'status', 'registration_date')
list_display_links = ('id', 'asker',)
list_filter = ('requester', 'due_date', 'service_type', 'status',
'registration_date')
search_fields = ('requester', 'due_date', 'service_type', 'status',
'registration_date')
ordering = ('-id',)
list_per_page = 25
formfield_overrides = {
OrderService.request: {'widget': Textarea(attrs={'class':
'custom-textarea'})},
}


@admin.register(MaintenanceService)
class MaintenanceService(admin.ModelAdmin):
list_display = ('id', 'description', 'value', 'type_service',
'is_minimum_tariff', 'minimum_tariff_value', 'registration_data')
list_display_links = ('id', 'description', 'value')
list_filter = ('description', 'value', 'type_service',
'is_minimum_tariff', 'minimum_tariff_value', 'registration_data')
search_fields = ('description', 'value', 'type_service',
'is_minimum_tariff', 'minimum_tariff_value', 'registration_data')
ordering = ('description', 'value', 'type_service',
'is_minimum_rate', 'minimum_rate_value', 'registration_date')
list_per_page = 10

But when I try to do it for multiples I get this error: 'list' object has
no attribute '_committed'

from .models import ServiceOrder, MaintenanceService
from django.contrib import admin
from django.forms import Textarea
from django import forms
from django.core.files import File
from django.core.files import File as DjangoFile


class MultipleFileInput(forms.ClearableFileInput):
allow_multiple_selected = True


class MultipleFileField(forms.FileField):
def __init__(self, *args, **kwargs):
kwargs.setdefault("widget", MultipleFileInput())
super().__init__(*args, **kwargs)

def clean(self, data, initial=None):
single_file_clean = super().clean
if isinstance(data, (list, tuple)):
result = [single_file_clean(d, initial) for d in data]
else:
result = single_file_clean(data, initial)
return result


class OrderServiceAdminForm(forms.ModelForm):
attachment = MultipleFileField(required=False)

class Meta:
model = ServiceOrder
fields="__all__"


# Register your models here.
@admin.register(ServiceOrder)
class OrderServiceAdmin(admin.ModelAdmin):
form = OrderServiceAdminForm

list_display = ('id', 'requester', 'due_date', 'service_type',
'notes', 'status', 'registration_date')
list_display_links = ('id', 'asker',)
list_filter = ('requester', 'due_date', 'service_type', 'status',
'registration_date')
search_fields = ('requester', 'due_date', 'service_type', 'status',
'registration_date')
ordering = ('-id',)
list_per_page = 25
formfield_overrides = {
OrderService.request: {'widget': Textarea(attrs={'class':
'custom-textarea'})},
}

def save_model(self, request, obj, form, change):
super().save_model(request, obj, form, change)

if form.cleaned_data.get('attachment'):
for file in form.cleaned_data['attached']:
file_obj = DjangoFile(file, name=file.name)
obj.attachment.create(file=file_obj)


@admin.register(MaintenanceService)
class MaintenanceService(admin.ModelAdmin):
list_display = ('id', 'description', 'value', 'type_service',
'is_minimum_tariff', 'minimum_tariff_value', 'registration_data')
list_display_links = ('id', 'description', 'value')
list_filter = ('description', 'value', 'type_service',
'is_minimum_tariff', 'minimum_tariff_value', 'registration_data')
search_fields = ('description', 'value', 'type_service',
'is_minimum_tariff', 'minimum_tariff_value', 'registration_data')
ordering = ('description', 'value', 'type_service',
'is_minimum_rate', 'minimum_rate_value', 'registration_date')
list_per_page = 10

--
Ticket URL: <https://code.djangoproject.com/ticket/34651>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

Django

unread,
Jun 13, 2023, 11:09:13 AM6/13/23
to django-...@googlegroups.com
#34651: 'list' object has no attribute '_committed'
-------------------------------------+-------------------------------------
Reporter: Vinícius Febasse | Owner: nobody
Type: | Status: closed
Cleanup/optimization |
Component: Uncategorized | Version: 4.2
Severity: Normal | Resolution: invalid

Keywords: | Triage Stage:
| Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Mariusz Felisiak):

* status: new => closed
* resolution: => invalid


Old description:

New description:

--

Comment:

Please use one of
[https://code.djangoproject.com/wiki/TicketClosingReasons/UseSupportChannels
support channels]. Trac is not one of them.

--
Ticket URL: <https://code.djangoproject.com/ticket/34651#comment:1>

Reply all
Reply to author
Forward
0 new messages