Advertisement
Guest User

Untitled

a guest
Apr 12th, 2019
122
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.05 KB | None | 0 0
  1. # Tabela domain
  2. MariaDB [opensips]> desc domain;
  3. +---------------+------------------+------+-----+---------------------+----------------+
  4. | Field | Type | Null | Key | Default | Extra |
  5. +---------------+------------------+------+-----+---------------------+----------------+
  6. | id | int(10) unsigned | NO | PRI | NULL | auto_increment |
  7. | domain | char(64) | NO | UNI | | |
  8. | attrs | char(255) | YES | | NULL | |
  9. | created_at | datetime | YES | | NULL | |
  10. | last_modified | datetime | NO | | 1900-01-01 00:00:01 | |
  11. +---------------+------------------+------+-----+---------------------+----------------+
  12.  
  13. MariaDB [opensips]> desc subscriber;
  14. +---------------+------------------+------+-----+---------+----------------+
  15. | Field | Type | Null | Key | Default | Extra |
  16. +---------------+------------------+------+-----+---------+----------------+
  17. | id | int(10) unsigned | NO | PRI | NULL | auto_increment |
  18. | username | char(64) | NO | MUL | | |
  19. | domain | char(64) | NO | | | |
  20. | password | char(25) | NO | | | |
  21. | email_address | char(64) | NO | | | |
  22. | ha1 | char(64) | NO | | | |
  23. | ha1b | char(64) | NO | | | |
  24. | rpid | char(64) | YES | | NULL | |
  25. +---------------+------------------+------+-----+---------+----------------+
  26. 8 rows in set (0.001 sec)
  27.  
  28.  
  29. ...
  30.  
  31.  
  32. import hashlib
  33.  
  34. from django.db import models
  35.  
  36.  
  37. class Domain(models.Model):
  38. """Model user to abstract 'domain' table."""
  39. domain = models.CharField(unique=True, max_length=64)
  40. attrs = models.CharField(max_length=255, blank=True, null=True)
  41. created_at = models.DateTimeField(auto_now_add=True)
  42. updated_at = models.DateTimeField(db_column='last_modified', auto_now=True)
  43.  
  44. class Meta:
  45. app_label = 'api'
  46. db_table = 'domain'
  47. ordering = ['domain']
  48. verbose_name = 'domain'
  49. verbose_name_plural = 'domains'
  50.  
  51.  
  52. class Subscriber(models.Model):
  53. """Model user to abstract 'subscriber' table."""
  54. username = models.CharField(max_length=64)
  55. domain = models.ForeignKey(
  56. 'Domain',
  57. on_delete=models.CASCADE,
  58. to_field='domain',
  59. related_name='domain'
  60. )
  61. email = models.CharField(db_column='email_address', max_length=64)
  62. rpid = models.CharField(max_length=64, blank=True, null=True)
  63.  
  64. _password = models.CharField(db_column='password', max_length=25)
  65. _ha1 = models.CharField(db_column='ha1', max_length=64)
  66. _ha1b = models.CharField(db_column='ha1b', max_length=64)
  67.  
  68. class Meta:
  69. app_label = 'api'
  70. db_table = 'subscriber'
  71. verbose_name = 'subscriber'
  72. ordering = ['username', 'domain']
  73. verbose_name_plural = 'subscribers'
  74. unique_together = [['username', 'domain']]
  75.  
  76. @property
  77. def password(self, value):
  78. """Property to automatize an hash generation of password."""
  79. self._password = value
  80. md5 = lambda x: hashlib.md5(str(x).encode('utf-8')).hexdigest()
  81. self._ha1 = md5('%s:%s:%s' % (self.username, self.domain, value))
  82. self._ha1b = md5('%s@%s:%s:%s' % (self.username, self.domain, self.domain, value))
  83.  
  84.  
  85. ERRO:
  86. api.Subscriber.domain: (fields.E302) Reverse accessor for 'Subscriber.domain' clashes with field name 'Domain.domain'.
  87. HINT: Rename field 'Domain.domain', or add/change a related_name argument to the definition for field 'Subscriber.domain'.
  88. api.Subscriber.domain: (fields.E303) Reverse query name for 'Subscriber.domain' clashes with field name 'Domain.domain'.
  89. HINT: Rename field 'Domain.domain', or add/change a related_name argument to the definition for field 'Subscriber.domain'.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement