There is a model Language
. Language objects creates Admin through Django-admin
. They have to choose from dropdown menu appropriate flag file.
The problem is that there is not flag to choice when I deploy project.
Since static files are being collected before deploy, I tried to set this path:
flag = models.FilePathField(path='static/img/flags/550px',default='')
But as you can see, it can't find anything.
I can choose from flags if I do this:
flag = models.FilePathField(path=settings.BASE_DIR+'/static/img/flags/550px',default='')
But then it doesn't work just calling language.flag
because it returns absolute path.
<img src = "{{ language.flag }}">
produce this:
<img src="/home/django/MyProject/static/img/flags/550px/ar.png">
The only solution which comes to my mind is to create a property which strips path
cutting "/home/django/MyProject/" but I'm not sure if it is a good idea.
Is there a better way?
class Language(models.Model):
shortcut = models.CharField(max_length=40,
help_text=_('Shortcut of the language'),
unique=True)
name = models.CharField(max_length=40,
help_text=_('Name of the language'),
unique=True, verbose_name=_("Language"))
flag = models.FilePathField(path='static/img/flags/550px',default='/static/img/icons/check-icon.png')
def __str__(self):
return self.name
EDIT:
Admin.py:
from django.contrib import admin
from models import Language
admin.site.register(Language)