Advertisement
Guest User

Untitled

a guest
Feb 7th, 2016
52
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.86 KB | None | 0 0
  1. class Trail(models.Model):
  2. '''
  3. Main model for this application. Contains all information for a particular trail
  4. '''
  5. trail_name = models.CharField(max_length=150)
  6. active = models.BooleanField(default=True)
  7. date_uploaded = models.DateTimeField(default=now())
  8. owner = models.ForeignKey(Account, default=1)
  9.  
  10. class Surface(models.Model):
  11. '''
  12. A many to many join table to map a surface type to many trails. A trail can have many
  13. surface types.
  14. '''
  15. type = models.CharField(max_length=50, db_column='surface_type', unique=True)
  16. trails = models.ManyToManyField(Trail)
  17.  
  18. class Meta:
  19. ordering = ('type', )
  20.  
  21. from django.models.db import Q
  22.  
  23. queries = [Q(type = surface) for surface in request.GET.getlist('keys')]
  24. query = queries.pop()
  25.  
  26. for item in queries:
  27. query |= item
  28.  
  29. results = Trail.objects.filter(surface=type)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement