Skip to content

Instantly share code, notes, and snippets.

@solanoize
Created July 1, 2017 08:38
Show Gist options
  • Select an option

  • Save solanoize/af5e02ff8e14660aba329c0120beba11 to your computer and use it in GitHub Desktop.

Select an option

Save solanoize/af5e02ff8e14660aba329c0120beba11 to your computer and use it in GitHub Desktop.
Custom FileField Bawaan Django untuk Membatasi Jenis File Image dan Sizenya
from .fields import ImageFieldRestrict
class Photo(models.Model):
user = models.ForeignKey('auth.User', related_name="user_photos")
booklet = models.ForeignKey(Booklet, related_name="photos")
about = models.CharField(max_length=100)
pic = ImageFieldRestrict(upload_to='photo/%Y/%m/%d')
created = models.DateTimeField(auto_now_add=True)
def __str__(self):
return self.booklet.title
class Meta:
ordering = ('-created',)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment