From 1a43303123eeeb5a5447774bb3fc7391af1338c2 Mon Sep 17 00:00:00 2001 From: Sanjay B Date: Sat, 1 Aug 2015 15:41:02 +0530 Subject: [PATCH] fix adding added by to inline relations, get entity image from gallery where available --- itf/app/models.py | 8 ++++++-- itf/insidepages/views.py | 9 +++++++++ 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/itf/app/models.py b/itf/app/models.py index df28a8a..c4ab935 100755 --- a/itf/app/models.py +++ b/itf/app/models.py @@ -263,8 +263,12 @@ class ItfModel(models.Model): imgfield = main_image_getter if imgfield is None or imgfield.name == '': - if self.get_modelextra(): - imgfield = self.get_modelextra().default_image + gallery_image = self.get_gallery_image() + if gallery_image: + imgfield = gallery_image + else: + if self.get_modelextra(): + imgfield = self.get_modelextra().default_image if imgfield: try: diff --git a/itf/insidepages/views.py b/itf/insidepages/views.py index c4af5b0..3f7910e 100755 --- a/itf/insidepages/views.py +++ b/itf/insidepages/views.py @@ -26,6 +26,10 @@ def add_object(request, module_slug, tab_slug): all_valid = True for inline in inlines: if inline.is_valid(): + inline_instances = inline.save(commit=False) + for inline_instance in inline_instances: + if inline_instance.__dict__.has_key('added_by_id'): + inline_instance.added_by = request.user inline.save() else: all_valid = False @@ -68,6 +72,11 @@ def edit_object(request, module_slug, tab_slug, object_id): all_valid = True for inline in inlines: if inline.is_valid(): + inline_instances = inline.save(commit=False) + for inline_instance in inline_instances: + if inline_instance.__dict__.has_key('added_by_id'): + if not inline_instance.added_by_id: + inline_instance.added_by = request.user inline.save() else: all_valid = False