it does not help, because I am image by default
class AccountUserInfo(models.Model):
MAN = 'man'
WOMAN = 'woman'
VAGUE = 'vague'
GENDER_CHOICES = [
(VAGUE, 'Vague'),
(MAN, 'Male'),
(WOMAN, 'Female'),
]
def dispatch_account_media_files(instance, filename):
return '{0}/app_accounts/{1}'.format(instance.account.__str__(), filename)
account = models.OneToOneField(AccountUser, on_delete=models.CASCADE)
first_name = models.CharField('First name', max_length=50, blank=True, null=True)
last_name = models.CharField('Last name', max_length=50, blank=True, null=True)
picture = models.ImageField('Picture', upload_to=dispatch_account_media_files, blank=True, null=True)
gender = models.CharField('Gender', max_length=10, choices=GENDER_CHOICES, default=GENDER_CHOICES[0][0])
country = CountryField('Country', blank_label='(select country)', blank=True, null=True)
birthday = models.DateField('Birthday', blank=True, null=True)
----------------------------------
@property
def picture_url(self):
if self.picture and hasattr(self.picture, 'url'):
return self.picture.url
else:
return '/project_static/images/default-picture.png'
But thanks for the advice
On Tue, Mar 1, 2016 at 5:23 PM, Jonas Svensson <jonas.s.svensson@gmail.com> wrote:
It seems like you want to use display a default picture if the user does not have one.--
{% load static %}{% static "images/default_pic.jpg" as default_pic %}{{ account.accountuserinfo.picture|default:default_pic }}
Cheers
On Monday, February 29, 2016 at 10:49:53 PM UTC+1, setivo...@gmail.com wrote:I need choice base url MEDIA_URL (/media/) - for uploaded user picture, or STATIC_URL (/static/) - picture by defaultI am try next:p><img src="{% if account.accountuserinfo.picture %}MEDIA{% else %}STATIC{% endif %}_URL{{ account.accountuserinfo.picture_url }}" alt="picture_for_{{ account.name }}" id="account_picture"></p>, but result is MEDIA_URL(STATIC_URL) and path to file.I am next try:but result is {{ MEDIA_URL }} or {{ STATIC_URL }} (not working)may by anyone known how solved this problem---------------------------------------------------Thanks
You received this message because you are subscribed to a topic in the Google Groups "Django users" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/django-users/5ZJzHbs1sYY/unsubscribe.
To unsubscribe from this group and all its topics, send an email to django-users+unsubscribe@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/ad20612d-2a90-4108-8737-d4bbe99a262c%40googlegroups.com.
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+unsubscribe@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/CAGWd_9KBPvrmeVGzNjfrmqAyV5%2BHZaAEsN0DjJtjxVOV2VG%2B1A%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.
No comments:
Post a Comment