This is my very first post on this awesome site, from which I have been finding answers to a handful of challenging questions. Kudos to the community!
I am new to the Django world, so am hoping to find help from some Django experts here. Thanks in advance.
Item model:
class Item(models.Model):
name = models.CharField(max_length=50)
ItemImage model:
class ItemImage(models.Model):
image = models.ImageField(upload_to=get_unique_filename)
item = models.ForeignKey(Item, related_name='images')
As you can tell from the model definitions above, every Item object can have many ItemImage objects.
My requirements are as followings:
Questions:
Considering that you are using file upload fields, I'm not sure that it's a right approach for web application. What if Item name validation fails? If you re-display the form again all file upload fields become empty and user has to fill them again.
Re technical side - ModelForm will do for the Item model but you should also use model formset for ItemImage's. See http://docs.djangoproject.com/en/dev/topics/forms/modelforms/#using-an-inline-formset-in-a-view for details.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.