2017-09-05 2 views
0

Ich habe ein Problem mit Django Bildfeld. Ich sollte Bild optional machen. Wenn der Administrator kein Bild hochgeladen hat, sollte django ein Standardbild hinzufügen. Wie kann das gemacht werden?Django wenn Bild nicht von Admin hochgeladen wurde Standardbild hinzufügen

Hier ist mein Code:

class News(models.Model): 
news_title = models.CharField(max_length=255) 
news_text = models.TextField(max_length=5000) 
news_short_text = models.CharField(max_length=255) 
news_logo = models.ImageField(upload_to='uimages', blank=True, null=True, default='') 
created_at = models.DateTimeField(auto_now_add=True) 
updated_at = models.DateTimeField(auto_now=True) 

Vielen Dank im Voraus

Antwort

4
news_logo = models.ImageField(
    upload_to='uimages', blank=True, null=True, 
    default='path to image after your media folder') 

das Bild auf den doppelten

+0

Abschnitt des Feldes default hinzufügen: https: //stackoverflow.com/questions/1276887/default-image-für-Bildfeld-in-djangos-orm –

Verwandte Themen