You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Image uploading in the first inline-level works fine, but in the second level or third level, it gets ignored. Nothing fails and the rest of the fields data get saved fine, but the file upload doesn't happen, the file is not in the server, and the corresponding entry in the database is not stored.
BTW, this is using Django 2.2.1 and code like the following:
models.py
class Course(models.Model):
name = models.CharField(max_length=255)
class Book(models.Model):
name = models.CharField(max_length=255)
course = models.ForeignKey(Course, on_delete=models.CASCADE)
class Lesson(models.Model):
name = models.CharField(max_length=255)
book = models.ForeignKey(Book, on_delete=models.CASCADE)
Seeing the same problem. My models aren't quite set up like yours, but similar.
When creating a brand new record in admin, the image doesn't save but all values do save ... KIND OF!
Not only does the image get ignored and not saved (I'm using S3 storage for images), but despite the other fields showing values in the admin, the related model's data isn't provided in either ListView or DetailView.
The only workaround that seems to work is to explicitly save the record twice. Create record like normal, filling out the fields, then hit 'save and continue editing' then add the image and then save again. Only after saving the record TWICE does the data get populated in ListView and DetailView, otherwise my {% for thing in things.all %} loop will trigger {% empty %}
Image is not saving because the enctype="multipart/form-data" attribute is missing in the form tag. So I found a workaround. I override the is_multipart method and returned true.
class LessonForm(forms.ModelForm):
def is_multipart(self):
return True
class LessonAdmin(NestedModelAdmin):
form = LessonForm
Image uploading in the first inline-level works fine, but in the second level or third level, it gets ignored. Nothing fails and the rest of the fields data get saved fine, but the file upload doesn't happen, the file is not in the server, and the corresponding entry in the database is not stored.
BTW, this is using Django 2.2.1 and code like the following:
models.py
class Course(models.Model):
name = models.CharField(max_length=255)
class Book(models.Model):
name = models.CharField(max_length=255)
course = models.ForeignKey(Course, on_delete=models.CASCADE)
class Lesson(models.Model):
name = models.CharField(max_length=255)
book = models.ForeignKey(Book, on_delete=models.CASCADE)
class LessonImage(models.Model):
image = models.ImageField(null=True, blank=True, upload_to="uploads/")
lesson = models.ForeignKey(Lesson, on_delete=models.CASCADE, related_name='lesson_image')
admin.py
class LessonImageInline(NestedStackedInline):
model = LessonImage
extra = 1
min_num = 0
class LessonInline(NestedStackedInline):
model = Lesson
extra = 1
min_num = 0
inlines = [LessonImageInline]
class BookInline(NestedStackedInline):
model = Book
extra = 1
min_num = 0
inlines = [LessonInline]
@admin.register(Course)
class CourseAdmin(NestedModelAdmin):
list_display = ('created_at', 'updated_at')
list_per_page = 50
inlines = [BookInline]
The text was updated successfully, but these errors were encountered: