Ticket #28972: models.py

File models.py, 1.4 KB (added by Kal Sze, 7 years ago)

models.py

Line 
1# -*- coding: utf-8 -*-
2
3# Django
4from django.conf import settings
5from django.contrib.auth import get_user_model
6from django.db import models
7
8# django-model-utils
9from model_utils.managers import InheritanceManager
10
11
12class 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
21class 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
27class 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
44class 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 )
Back to Top