Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # Tabela domain
- MariaDB [opensips]> desc domain;
- +---------------+------------------+------+-----+---------------------+----------------+
- | Field | Type | Null | Key | Default | Extra |
- +---------------+------------------+------+-----+---------------------+----------------+
- | id | int(10) unsigned | NO | PRI | NULL | auto_increment |
- | domain | char(64) | NO | UNI | | |
- | attrs | char(255) | YES | | NULL | |
- | created_at | datetime | YES | | NULL | |
- | last_modified | datetime | NO | | 1900-01-01 00:00:01 | |
- +---------------+------------------+------+-----+---------------------+----------------+
- MariaDB [opensips]> desc subscriber;
- +---------------+------------------+------+-----+---------+----------------+
- | Field | Type | Null | Key | Default | Extra |
- +---------------+------------------+------+-----+---------+----------------+
- | id | int(10) unsigned | NO | PRI | NULL | auto_increment |
- | username | char(64) | NO | MUL | | |
- | domain | char(64) | NO | | | |
- | password | char(25) | NO | | | |
- | email_address | char(64) | NO | | | |
- | ha1 | char(64) | NO | | | |
- | ha1b | char(64) | NO | | | |
- | rpid | char(64) | YES | | NULL | |
- +---------------+------------------+------+-----+---------+----------------+
- 8 rows in set (0.001 sec)
- ...
- import hashlib
- from django.db import models
- class Domain(models.Model):
- """Model user to abstract 'domain' table."""
- domain = models.CharField(unique=True, max_length=64)
- attrs = models.CharField(max_length=255, blank=True, null=True)
- created_at = models.DateTimeField(auto_now_add=True)
- updated_at = models.DateTimeField(db_column='last_modified', auto_now=True)
- class Meta:
- app_label = 'api'
- db_table = 'domain'
- ordering = ['domain']
- verbose_name = 'domain'
- verbose_name_plural = 'domains'
- class Subscriber(models.Model):
- """Model user to abstract 'subscriber' table."""
- username = models.CharField(max_length=64)
- domain = models.ForeignKey(
- 'Domain',
- on_delete=models.CASCADE,
- to_field='domain',
- related_name='subscribers_domain'
- db_column="domain"
- )
- email = models.CharField(db_column='email_address', max_length=64)
- rpid = models.CharField(max_length=64, blank=True, null=True)
- _password = models.CharField(db_column='password', max_length=25)
- _ha1 = models.CharField(db_column='ha1', max_length=64)
- _ha1b = models.CharField(db_column='ha1b', max_length=64)
- class Meta:
- app_label = 'api'
- db_table = 'subscriber'
- verbose_name = 'subscriber'
- ordering = ['username', 'domain']
- verbose_name_plural = 'subscribers'
- unique_together = [['username', 'domain']]
- @property
- def password(self, value):
- """Property to automatize an hash generation of password."""
- self._password = value
- md5 = lambda x: hashlib.md5(str(x).encode('utf-8')).hexdigest()
- self._ha1 = md5('%s:%s:%s' % (self.username, self.domain, value))
- self._ha1b = md5('%s@%s:%s:%s' % (self.username, self.domain, self.domain, value))
- ERRO:
- api.Subscriber.domain: (fields.E302) Reverse accessor for 'Subscriber.domain' clashes with field name 'Domain.domain'.
- HINT: Rename field 'Domain.domain', or add/change a related_name argument to the definition for field 'Subscriber.domain'.
- api.Subscriber.domain: (fields.E303) Reverse query name for 'Subscriber.domain' clashes with field name 'Domain.domain'.
- 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