def test_get_related_objects_admin_urls_from_model_inline_with_image(self): with search.update_index(): self.test_page_model = Page.objects.create( title='Test page', content_type=ContentType.objects.get_for_model( TestContentBase), ) self.test_content_base = TestContentBase.objects.create( page=self.test_page_model, ) test_model_1a_inline = TestModelOneInline.objects.create( parent=self.test_model_1a, image=self.test_file) self.clear_image_references( [self.test_model_1a, self.test_model_1b, self.test_model_2a]) expected_outcome = [ { 'title': str(test_model_1a_inline), 'model_name': test_model_1a_inline._meta.verbose_name, 'admin_url': reverse( f'admin:{self.test_model_1a._meta.app_label}_{self.test_model_1a._meta.model_name}_change', args=[self.test_model_1a.pk]), }, ] self.assertEqual(get_related_objects_admin_urls(self.test_file), expected_outcome)
def used_on(self, obj=None): context = {} if obj: context['related_objects'] = get_related_objects_admin_urls(obj) else: context['related_objects'] = [] return render_to_string('admin/media/includes/file_used_on.html', context)
def test_get_related_objects_admin_urls_from_models_with_other_image(self): expected_outcome = [{ 'title': str(obj), 'model_name': obj._meta.verbose_name, 'admin_url': reverse( f'admin:{obj._meta.app_label}_{obj._meta.model_name}_change', args=[obj.pk]), } for obj in [self.test_model_1a_other, self.test_model_2a_other]] self.assertEqual(get_related_objects_admin_urls(self.other_test_file), expected_outcome)
def test_get_related_objects_admin_urls_from_models_with_image(self): # We have an instance of File (eg: self.test_file) # We have a Model with an ImageRefField (eg: self.test_model_1a) # We need to check that we can get the expected related objects when passing the file reference to get_related_objects_admin_urls() expected_outcome = [{ 'title': str(obj), 'model_name': obj._meta.verbose_name, 'admin_url': reverse( f'admin:{obj._meta.app_label}_{obj._meta.model_name}_change', args=[obj.pk]), } for obj in [ self.test_model_1a, self.test_model_1b, self.test_model_2a ]] self.assertEqual(get_related_objects_admin_urls(self.test_file), expected_outcome)