Skip to content

Instantly share code, notes, and snippets.

@alfredrumss
Last active June 28, 2016 15:10
Show Gist options
  • Save alfredrumss/92b42f7c5f5c7cc803b66b709b73f2cd to your computer and use it in GitHub Desktop.
Save alfredrumss/92b42f7c5f5c7cc803b66b709b73f2cd to your computer and use it in GitHub Desktop.
class Departament(models.Model):
name = models.CharField(max_length=100)
description = models.CharField(max_length=500, blank=True)
status = models.BooleanField(default=False, blank=True)
created_at = models.DateTimeField(auto_now_add=True, blank=True)
def __unicode__(self):
return self.name
class Area(models.Model):
departament = models.ForeignKey(Departament, on_delete= models.CASCADE, related_name="areas")
description = models.CharField(max_length=500, blank=True)
name = models.CharField(max_length=100)
status = models.BooleanField(default=False, blank=True)
created_at = models.DateTimeField(auto_now_add=True, blank=True)
def __unicode__(self):
return self.name
class AreaSerializer(serializers.ModelSerializer):
class Meta:
depth = 1
model = Area
class DepartamentSerializer(serializers.ModelSerializer):
areas = AreaSerializer(read_only=True, many=True)
class Meta:
model = Departament
fields = ('id' ,'name', 'description','status', 'areas', 'created_at',)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment