from django.db import models
from mptt.models import MPTTModel, TreeForeignKey

# Create your models here.
class Folder(MPTTModel):
	name = models.CharField(blank=True,null=True,max_length=128)
	icon = models.FileField(blank=True,null=True)
	parent = TreeForeignKey('self', null=True, blank=True, on_delete=models.CASCADE, related_name='children')
	
	def __str__(self):
		if self.name != None:
			result = self.name
		else:
			result = "Dossier Sans Nom"
		return result

	class MPTTMeta:
		order_insertion_by = ['name']

	class Meta:
		verbose_name = "Dossier"
		verbose_name_plural = "Dossiers"

	def subfolder_count(self):
		return self.children.count()

class Document(models.Model):
	name = models.CharField(blank=True,null=True,max_length=128)
	description = models.TextField(blank=True,null=True)
	file = models.FileField(blank=True,null=True)
	folder = models.ForeignKey(Folder, on_delete=models.CASCADE, null=True, blank=True)
	def __str__(self):
		if self.name != None:
			result = self.name
		else:
			result = str(self.file)
		return result

class Network(models.Model):
	name = models.CharField(blank=True,null=True,max_length=128)
	description = models.TextField(blank=True,null=True)
	link = models.CharField(blank=True,null=True,max_length=128)
	def __str__(self):
		if self.name != None:
			result = self.name
		else:
			result = "Reseau non identifie"
		return result
		
class InfoGeneral(models.Model):
	nom = models.CharField(max_length=64,blank=True,null=True)
	code = models.CharField(max_length=64,blank=True,null=True)
	value = models.CharField(max_length=64,blank=True,null=True)


"""
class Dossier(models.Model):
	name = models.CharField(blank=True,null=True,max_length=128)
	description = models.TextField(blank=True,null=True)
	link = models.CharField(blank=True,null=True,max_length=128)
	def __str__(self):
		return self.name
"""
