Advertisement
Guest User

Untitled

a guest
Aug 4th, 2015
173
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.57 KB | None | 0 0
  1. class MatrilineAdmin(sqla.ModelView):
  2.  
  3. form_extra_fields = {
  4. 'clan': SelectField('Clan',
  5. coerce=int,
  6. choices=[ (c.id, c.name) for c in Clan.query.all()])
  7. }
  8. create_template = 'admin/create.html'
  9. edit_template = 'admin/edit.html'
  10.  
  11. def on_form_prefill(self, form, id):
  12. form.clan.choices = [(1, "first"),(2,"second")]
  13. form.clan.default = 2
  14. form.process() # if commented, set choices but does not set default
  15. # else set choices and default but delete all the other fields values (name and pod_id)
  16.  
  17. class Matriline(db.Model):
  18. __tablename__ = 'matriline'
  19. id = db.Column(db.Integer, primary_key=True)
  20. name = db.Column(db.Unicode(64))
  21. calls = db.relationship('Call', backref='matriline', lazy='select')
  22. pod_id = db.Column(db.Integer, db.ForeignKey('pod.id'))
  23.  
  24. def __unicode__(self):
  25. return self.name
  26.  
  27. def __str__(self):
  28. return self.name
  29.  
  30.  
  31. class Pod(db.Model):
  32. __tablename__ = 'pod'
  33. id = db.Column(db.Integer, primary_key=True)
  34. name = db.Column(db.Unicode(64))
  35. matrilines = db.relationship('Matriline', backref='pod', lazy='select')
  36. clan_id = db.Column(db.Integer, db.ForeignKey('clan.id'))
  37.  
  38. def __unicode__(self):
  39. return self.name
  40. def __str__(self):
  41. return self.name
  42.  
  43.  
  44. class Clan(db.Model):
  45. __tablename__ = 'clan'
  46. id = db.Column(db.Integer, primary_key=True)
  47. name = db.Column(db.Unicode(64))
  48. pods = db.relationship('Pod', backref='clan', lazy='select')
  49.  
  50. def __unicode__(self):
  51. return self.name
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement