Created
August 30, 2018 11:21
-
-
Save niko86/a437fe6ac2ca6b9c9f3d1b0b7ca83003 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 Project(models.Model): | |
project_code = models.CharField(max_length=7, unique=True) | |
class Hole(models.Model): | |
hole_number = models.CharField(max_length=16) | |
project = models.ForeignKey('Project', on_delete=models.CASCADE, | |
blank=True, null=True, related_name='holes', verbose_name='Project') | |
class Description(models.Model): | |
depth_top = models.DecimalField(max_digits=5, decimal_places=2) | |
depth_base = models.DecimalField(max_digits=5, decimal_places=2) | |
content = models.CharField(max_length=512) | |
hole = models.ForeignKey('Hole', on_delete=models.CASCADE, blank=True, | |
null=True, related_name='descriptions', verbose_name='Hole') | |
def get_by_proj(proj_id, hole_id, depth_top, depth_base): | |
p = Description.objects.filter(hole__project__project_code=proj_id) \ | |
.filter(hole__hole_number=hole_id) \ | |
.filter(depth_top=float(depth_top), depth_base=float(depth_base)) \ | |
.first() # working up from bottom to top | |
print(p) | |
return { | |
'project_id': p.hole.project.project_code, | |
'hole_id': p.hole.hole_number, | |
'depth_top': p.depth_top, | |
'depth_base': p.depth_base, | |
'content': p.content, | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment