A
A
Alexander2016-04-13 15:08:42
Django
Alexander, 2016-04-13 15:08:42

How to get data id from forms.py?

from django import forms
from lev.Libary.Upload import Upload
from .models import Product
from multiupload.fields import MultiFileField


class ProductForm(forms.ModelForm):
    image = MultiFileField(max_num=5)

    class Meta:
        model = Product
        fields = ('title', 'short_text', 'text', 'alias', 'category', 'status', 'image')

    def clean_image(self):
        Upload.UploadFiles(self.cleaned_data.get('image'))

I want to get the data id of those that come in the clean_image method.
print(self.cleaned_data) shows all data except id
data from print:
{'category': <Category: ASAS>, 'image': [<InMemoryUploadedFile: 4to.jpg (image/jpeg)>], 'title': '123123', 'short_text': 'asdsad', 'alias': 'adasd', 'status': True, 'text': 'dasd'}

Answer the question

In order to leave comments, you need to log in

1 answer(s)
V
Vladimir Kuts, 2016-04-13
@kentuck1213

Intercept directly from the instance:

def clean_image(self):
        my_id = self.instance.id
        Upload.UploadFiles(self.cleaned_data.get('image'))

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question