diff options
author | Filipp Lepalaan <filipp@mac.com> | 2021-05-12 14:48:56 +0300 |
---|---|---|
committer | Filipp Lepalaan <filipp@mac.com> | 2021-05-12 14:48:56 +0300 |
commit | 05211dca7f3dd6b15353f22ae7e1320fb676c917 (patch) | |
tree | 55509740b6651df20843b9d646133f7394d0467d /servo | |
parent | 6bc5a96727aa4f7ac36dc996b6f996a05986aba5 (diff) | |
download | Servo-05211dca7f3dd6b15353f22ae7e1320fb676c917.tar.gz Servo-05211dca7f3dd6b15353f22ae7e1320fb676c917.tar.bz2 Servo-05211dca7f3dd6b15353f22ae7e1320fb676c917.zip |
Stopped using Sites. Added Django 3 req fields
Diffstat (limited to 'servo')
-rw-r--r-- | servo/models/common.py | 82 |
1 files changed, 31 insertions, 51 deletions
diff --git a/servo/models/common.py b/servo/models/common.py index b2b6c51..81e6855 100644 --- a/servo/models/common.py +++ b/servo/models/common.py @@ -3,12 +3,10 @@ import gsxws import os.path -from django.core.urlresolvers import reverse +from django.urls import reverse from django.template.defaultfilters import slugify from pytz import common_timezones, country_timezones -from django.contrib.sites.models import Site - from django.db import models from django.conf import settings @@ -20,9 +18,6 @@ from django.utils.translation import ugettext_lazy as _ from django.dispatch import receiver from django.db.models.signals import post_save -from django.contrib.contenttypes.models import ContentType -from django.contrib.contenttypes.fields import GenericForeignKey - from django.core.cache import cache from servo import defaults @@ -75,33 +70,14 @@ class CsvTable(object): return unicode(self).encode('utf-8') -class BaseItem(models.Model): - """ - Base class for a few generic relationships - """ - object_id = models.PositiveIntegerField() - content_type = models.ForeignKey(ContentType) - content_object = GenericForeignKey("content_type", "object_id") - - class Meta: - abstract = True - app_label = "servo" - -class RatedItem(BaseItem): - rating = models.PositiveIntegerField() - - -class TimedItem(BaseItem): - status = models.CharField(max_length=128) - started_at = models.DateTimeField() - timeout_at = models.DateTimeField() - - -class TaggedItem(BaseItem): +class TaggedItem(models.Model): """ A generic tagged item """ + ref = models.CharField(max_length=32) + ref_id = models.IntegerField() + tag = models.CharField(max_length=128) slug = models.SlugField() color = models.CharField(max_length=8, default="") @@ -115,20 +91,29 @@ class TaggedItem(BaseItem): class Meta: app_label = "servo" - unique_together = ("content_type", "object_id", "tag",) + unique_together = ("ref", "ref_id", "tag",) -class FlaggedItem(BaseItem): - flagged_by = models.ForeignKey(settings.AUTH_USER_MODEL) +class FlaggedItem(models.Model): + ref = models.CharField(max_length=32) + ref_id = models.IntegerField() + flagged_by = models.ForeignKey( + settings.AUTH_USER_MODEL, + on_delete=models.SET_NULL + ) -class Event(BaseItem): +class Event(models.Model): """ Something that happens """ - description = models.CharField(max_length=255) + ref = models.CharField(max_length=32) + ref_id = models.IntegerField() - triggered_by = models.ForeignKey(settings.AUTH_USER_MODEL) + description = models.CharField(max_length=255) + triggered_by = models.ForeignKey( + settings.AUTH_USER_MODEL, + on_delete=models.SET_NULL) triggered_at = models.DateTimeField(auto_now_add=True) handled_at = models.DateTimeField(null=True) @@ -170,12 +155,6 @@ class Event(BaseItem): class GsxAccount(models.Model): - site = models.ForeignKey( - Site, - editable=False, - default=defaults.site_id - ) - title = models.CharField(max_length=128, default=_("New GSX Account")) sold_to = models.CharField(max_length=10, verbose_name=_("Sold-To")) ship_to = models.CharField(max_length=10, verbose_name=_("Ship-To")) @@ -342,7 +321,8 @@ class Tag(MPTTModel): 'self', null=True, blank=True, - related_name='children' + related_name='children', + on_delete=models.SET_NULL, ) times_used = models.IntegerField(default=0, editable=False) @@ -393,13 +373,9 @@ class LocationManager(models.Manager): class Location(models.Model): - """A Service Location within a company.""" - - site = models.ForeignKey( - Site, - editable=False, - default=defaults.site_id - ) + """ + A Service Location within a company. + """ title = models.CharField( max_length=255, @@ -479,6 +455,7 @@ class Location(models.Model): settings.AUTH_USER_MODEL, null=True, blank=True, + on_delete=models.SET_NULL, related_name="managed_locations", limit_choices_to={'is_visible': True} ) @@ -544,7 +521,7 @@ class Location(models.Model): class Configuration(models.Model): - site = models.ForeignKey(Site, editable=False, default=defaults.site_id) + key = models.CharField(max_length=255) value = models.TextField(default='', blank=True) @@ -775,9 +752,12 @@ class Template(models.Model): verbose_name_plural = _('Templates') -class Attachment(BaseItem): +class Attachment(models.Model): """A file attached to something.""" + ref = models.CharField(max_length=32) + ref_id = models.IntegerField() + mime_type = models.CharField(max_length=64, editable=False) content = models.FileField( upload_to='attachments', |