Advertisement
Guest User

Untitled

a guest
Apr 12th, 2019
163
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.08 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='subscribers_domain'
  60. db_column="domain"
  61. )
  62. email = models.CharField(db_column='email_address', max_length=64)
  63. rpid = models.CharField(max_length=64, blank=True, null=True)
  64.  
  65. _password = models.CharField(db_column='password', max_length=25)
  66. _ha1 = models.CharField(db_column='ha1', max_length=64)
  67. _ha1b = models.CharField(db_column='ha1b', max_length=64)
  68.  
  69. class Meta:
  70. app_label = 'api'
  71. db_table = 'subscriber'
  72. verbose_name = 'subscriber'
  73. ordering = ['username', 'domain']
  74. verbose_name_plural = 'subscribers'
  75. unique_together = [['username', 'domain']]
  76.  
  77. @property
  78. def password(self, value):
  79. """Property to automatize an hash generation of password."""
  80. self._password = value
  81. md5 = lambda x: hashlib.md5(str(x).encode('utf-8')).hexdigest()
  82. self._ha1 = md5('%s:%s:%s' % (self.username, self.domain, value))
  83. self._ha1b = md5('%s@%s:%s:%s' % (self.username, self.domain, self.domain, value))
  84.  
  85.  
  86. ERRO:
  87. api.Subscriber.domain: (fields.E302) Reverse accessor for 'Subscriber.domain' clashes with field name 'Domain.domain'.
  88. HINT: Rename field 'Domain.domain', or add/change a related_name argument to the definition for field 'Subscriber.domain'.
  89. api.Subscriber.domain: (fields.E303) Reverse query name for 'Subscriber.domain' clashes with field name 'Domain.domain'.
  90. 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