from django.db import models
from django.contrib.auth.models import User, Permission
from django.db.models.signals import post_save, pre_delete, post_delete
from PIL import Image

import os
import settings

def makeSimulationImage(instance, filename):
	return filename
	
class Simulation(models.Model):
	user = models.ForeignKey(User, null=True)
	image = models.ImageField(upload_to = makeSimulationImage)
	cache_str = models.CharField(max_length=128)

def delete_simulation_data(sender, instance, **kwargs):
	try:
		instance.image.delete(save=False)
	except:
		pass

post_delete.connect(delete_simulation_data, sender=Simulation)