Re: Best way to add an image from a filefield to django 2.0 admin?

2018-06-06 Thread Mark Phillips
Daniel,

I did read the docs and could not get it to work. Probably operator error,
as I went back a day later and followed the docs, and it worked as
advertised!

In the interest of completeness, here are the snippets of what I did:

class DocumentMetaDataAdmin(admin.ModelAdmin):
readonly_fields = ('get_image_2', )

fieldsets = (
(None, {
'fields': ('get_image_2', ),
'classes': ('extrapretty', ),
}),
)

def get_image_2(self, obj):
image = ""   # need to add a default image
if (obj.document_id.storage_file_name):
image = ''.format(image_link =
obj.document_id.storage_file_name.url, thumb_nail =
obj.document_id.storage_file_name.url)
return format_html(image)

Thanks!

Mark

PS Still working on defining the 'extrapretty' CSS!

On Wed, Jun 6, 2018 at 5:17 AM, Daniel Germano Travieso <
danielgtravi...@gmail.com> wrote:

> Hello Mark.
>
> You can just override the Model Admin for your model and insert an Inline
> Form for example.
>
> Check the documentation for customizing the model admin!
>
> Hope it helps!
>
>
> On Mon, Jun 4, 2018, 18:02 Mark Phillips 
> wrote:
>
>> I have a Document model that uploads an image. I have a DocumentMetaData
>> model with a JSON field where I "crud" metadata for the documents in the
>> Document model.
>>
>> I would like to add the image of the document in the Document model to
>> the change form of the DocumentMetaData model in the admin. How do I do it?
>> Do I have to override the admin/change_form.html for the DocumentMetaData
>> model?
>>
>> Thanks!
>>
>> Mark
>>
>> --
>> You received this message because you are subscribed to the Google Groups
>> "Django users" group.
>> To unsubscribe from this group and stop receiving emails from it, send an
>> email to django-users+unsubscr...@googlegroups.com.
>> To post to this group, send email to django-users@googlegroups.com.
>> Visit this group at https://groups.google.com/group/django-users.
>> To view this discussion on the web visit https://groups.google.com/d/
>> msgid/django-users/CAEqej2PYNudeSWa5CY934m8kMWO%
>> 3Dhcpj4%3DxQud9C-wZCHoaS4g%40mail.gmail.com
>> 
>> .
>> For more options, visit https://groups.google.com/d/optout.
>>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to django-users+unsubscr...@googlegroups.com.
> To post to this group, send email to django-users@googlegroups.com.
> Visit this group at https://groups.google.com/group/django-users.
> To view this discussion on the web visit https://groups.google.com/d/
> msgid/django-users/CABF8kZOWiPDeDrtTbuytOD8Nm%
> 3DHqd1A%2BtwNKSkmmEyk85jVGzA%40mail.gmail.com
> 
> .
> For more options, visit https://groups.google.com/d/optout.
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CAEqej2MG8f2kV5W68tYdgyYGm0d2Lr_O9ieKVOoNY%2BK8SKEP7A%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: Best way to add an image from a filefield to django 2.0 admin?

2018-06-06 Thread Daniel Germano Travieso
Hello Mark.

You can just override the Model Admin for your model and insert an Inline
Form for example.

Check the documentation for customizing the model admin!

Hope it helps!


On Mon, Jun 4, 2018, 18:02 Mark Phillips  wrote:

> I have a Document model that uploads an image. I have a DocumentMetaData
> model with a JSON field where I "crud" metadata for the documents in the
> Document model.
>
> I would like to add the image of the document in the Document model to the
> change form of the DocumentMetaData model in the admin. How do I do it? Do
> I have to override the admin/change_form.html for the DocumentMetaData
> model?
>
> Thanks!
>
> Mark
>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to django-users+unsubscr...@googlegroups.com.
> To post to this group, send email to django-users@googlegroups.com.
> Visit this group at https://groups.google.com/group/django-users.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/CAEqej2PYNudeSWa5CY934m8kMWO%3Dhcpj4%3DxQud9C-wZCHoaS4g%40mail.gmail.com
> 
> .
> For more options, visit https://groups.google.com/d/optout.
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CABF8kZOWiPDeDrtTbuytOD8Nm%3DHqd1A%2BtwNKSkmmEyk85jVGzA%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Best way to add an image from a filefield to django 2.0 admin?

2018-06-04 Thread Mark Phillips
I have a Document model that uploads an image. I have a DocumentMetaData
model with a JSON field where I "crud" metadata for the documents in the
Document model.

I would like to add the image of the document in the Document model to the
change form of the DocumentMetaData model in the admin. How do I do it? Do
I have to override the admin/change_form.html for the DocumentMetaData
model?

Thanks!

Mark

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CAEqej2PYNudeSWa5CY934m8kMWO%3Dhcpj4%3DxQud9C-wZCHoaS4g%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.