Advertisement
Guest User

Untitled

a guest
Feb 15th, 2016
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.08 KB | None | 0 0
  1. class User(models.Model):
  2. id = models.AutoField(primary_key=True)
  3. username = models.CharField(unique=True, max_length=120,blank=False)
  4. password = models.CharField(max_length=120, blank=True, null=False)
  5.  
  6. class Record(models.Model):
  7.  
  8. id = models.AutoField(primary_key=True)
  9. name = models.CharField(max_length=120, unique=True, blank=True)
  10. followers = models.ManyToManyField(User, through='Follow')
  11.  
  12. class Record(models.Model):
  13.  
  14. id = models.AutoField(primary_key=True)
  15. record = models.ForeignKey(Record)
  16. user = models.ForeignKey(User)
  17. date_followed = models.DateField(null=True, blank=True)
  18.  
  19. {% for i in records %}
  20.  
  21. {% if i.follow.filter(id='1').first() %}
  22. DO SOMETHING
  23. {% endif %}
  24.  
  25. {% endfor %}
  26.  
  27. TemplateSyntaxError at /records/
  28. Could not parse the remainder: '(id='1').first()' from 'i.follow.filter(id='1').first()'
  29.  
  30. >>> x = Record.objects.first()
  31. >>> x.followers.filter(id='1').first()
  32. <User: User object>
  33.  
  34. {% for i in accounts %}
  35.  
  36. {% if i.follow.filter_by(user_id='1').first() %}
  37. DO SOMETHING
  38. {% endif %}
  39.  
  40. {% endfor %}
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement