Re: [Django] #31725: Setting ImageField and FileField default to a static file

2020-06-22 Thread Django
#31725: Setting ImageField and FileField default to a static file
-+-
 Reporter:  Daniel González  |Owner:  nobody
  Fernández  |
 Type:  New feature  |   Status:  closed
Component:  Database layer   |  Version:  3.0
  (models, ORM)  |
 Severity:  Normal   |   Resolution:  wontfix
 Keywords:  static image | Triage Stage:
  default|  Unreviewed
Has patch:  0|  Needs documentation:  0
  Needs tests:  0|  Patch needs improvement:  0
Easy pickings:  0|UI/UX:  0
-+-
Changes (by Carlton Gibson):

 * status:  new => closed
 * resolution:   => wontfix


Comment:

 Yes, I think if there's no image then setting `null=True` is correct. You
 **could** use a custom field to encapsulate the placeholder handling but
 it strikes me doing it at the presentation layer is fine.

-- 
Ticket URL: 
Django 
The Web framework for perfectionists with deadlines.

-- 
You received this message because you are subscribed to the Google Groups 
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-updates+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-updates/068.2bfa01c1811f9914bfbc1401727b0ab9%40djangoproject.com.


Re: [Django] #31725: Setting ImageField and FileField default to a static file

2020-06-21 Thread Django
#31725: Setting ImageField and FileField default to a static file
-+-
 Reporter:  Daniel González  |Owner:  nobody
  Fernández  |
 Type:  New feature  |   Status:  new
Component:  Database layer   |  Version:  3.0
  (models, ORM)  |
 Severity:  Normal   |   Resolution:
 Keywords:  static image | Triage Stage:
  default|  Unreviewed
Has patch:  0|  Needs documentation:  0
  Needs tests:  0|  Patch needs improvement:  0
Easy pickings:  0|UI/UX:  0
-+-

Comment (by Alexandr Tatarinov):

 I am not sure this should be solved on the model level, because IMHO it is
 related to the presentation level, so I would suggest solving this on
 Form/Template level.
 When using i.e. DRF I would place `get_avatar` in the serializer and use
 `SerializerMethodField`. Also, I believe this can be solved on an
 individual codebase level without the need to integrate into Django.

-- 
Ticket URL: 
Django 
The Web framework for perfectionists with deadlines.

-- 
You received this message because you are subscribed to the Google Groups 
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-updates+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-updates/068.9bbef916dd04a6fc103c0793d14c7267%40djangoproject.com.


[Django] #31725: Setting ImageField and FileField default to a static file

2020-06-19 Thread Django
#31725: Setting ImageField and FileField default to a static file
-+-
   Reporter:  Daniel |  Owner:  nobody
  González Fernández |
   Type:  New| Status:  new
  feature|
  Component:  Database   |Version:  3.0
  layer (models, ORM)|   Keywords:  static image
   Severity:  Normal |  default
   Triage Stage: |  Has patch:  0
  Unreviewed |
Needs documentation:  0  |Needs tests:  0
Patch needs improvement:  0  |  Easy pickings:  0
  UI/UX:  0  |
-+-
 I think that the user who made this comment
 (https://code.djangoproject.com/ticket/25905#comment:8) makes a valid
 point.

 This is an important issue because currently, it doesn't allow to serve as
 default an static file (this is useful for example when setting a default
 avatar image in a user models, and in many others use's cases, as it allow
 to have many objects referencing the same file, instead of each one of
 them having a copy)

 In development, where is a common practice to have the media and static
 folders in the root of the project, this is easily solved by doing:
 {{{
 avatar = ImageField(default="../static/default_avatar.png", blank=True).
 }}}
 But what about production, when you usually serve your static files from a
 CND or solucions like AWS S3 ???

 The best solution I've come up with so far is to allow that field to be
 null, and explicitly right the get method of that field:
 {{{
 avatar = ImageField(blank=True, null=true)

 def get_avatar(self):
 # variable PATH_TO_DEFAULT_STATIC_IMAGE depends on the enviroment
 # on development, it would be something like
 "localhost:8000/static/default_avatar.png"
 # on production, it would be something like
 "https://BUCKET_NAME.s3.amazonaws.com/static/default_avatar.png";
 return self.avatar if self.avatar else 
 }}}

 However, it does look a little bit over-engineer, considering that most of
 the time, the default is an static file.

-- 
Ticket URL: 
Django 
The Web framework for perfectionists with deadlines.

-- 
You received this message because you are subscribed to the Google Groups 
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-updates+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-updates/053.75632c2f33d720dfc8132002158a09d9%40djangoproject.com.