Last active
June 28, 2016 15:10
-
-
Save alfredrumss/92b42f7c5f5c7cc803b66b709b73f2cd to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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