1 | # -*- coding: utf-8 -*-
|
---|
2 |
|
---|
3 | # Django
|
---|
4 | from django.conf import settings
|
---|
5 | from django.contrib.auth import get_user_model
|
---|
6 | from django.db import models
|
---|
7 |
|
---|
8 | # django-model-utils
|
---|
9 | from model_utils.managers import InheritanceManager
|
---|
10 |
|
---|
11 |
|
---|
12 | class BaseLicense(models.Model):
|
---|
13 | #objects = InheritanceManager()
|
---|
14 |
|
---|
15 | user = models.ForeignKey(settings.AUTH_USER_MODEL, on_delete=models.PROTECT)
|
---|
16 |
|
---|
17 | def __str__(self):
|
---|
18 | return 'BaseLicense<{0}>'.format(self.id)
|
---|
19 |
|
---|
20 |
|
---|
21 | class LicenseManager(models.Manager):
|
---|
22 | def get_by_natural_key(self, user_nk, license_key):
|
---|
23 | user = get_user_model().objects.get_by_natural_key(*user_nk)
|
---|
24 | return self.get(user=user, license_key=license_key)
|
---|
25 |
|
---|
26 |
|
---|
27 | class AdobePhotoshopLicense(BaseLicense):
|
---|
28 | license_key = models.TextField()
|
---|
29 |
|
---|
30 | objects = LicenseManager()
|
---|
31 |
|
---|
32 | def natural_key(self):
|
---|
33 | return (self.user.natural_key(), self.license_key)
|
---|
34 |
|
---|
35 | natural_key.dependencies = [settings.AUTH_USER_MODEL]
|
---|
36 |
|
---|
37 | def __str__(self):
|
---|
38 | return 'AdobePhotoshopLicense<{0}, {1}>'.format(
|
---|
39 | self.user.email,
|
---|
40 | self.license_key,
|
---|
41 | )
|
---|
42 |
|
---|
43 |
|
---|
44 | class CorelDrawLicense(BaseLicense):
|
---|
45 | license_key = models.TextField()
|
---|
46 |
|
---|
47 | objects = LicenseManager()
|
---|
48 |
|
---|
49 | def natural_key(self):
|
---|
50 | return (self.user.natural_key(), self.license_key)
|
---|
51 |
|
---|
52 | natural_key.dependencies = [settings.AUTH_USER_MODEL]
|
---|
53 |
|
---|
54 | def __str__(self):
|
---|
55 | return 'CorelDrawLicense<{0}, {1}>'.format(
|
---|
56 | self.user.email,
|
---|
57 | self.license_key,
|
---|
58 | )
|
---|