我正在使用最新版本的 Django 和 DRF。但是在运行它之后,我收到了这个错误:
类 HStoreDescriptor(models.fields.subclassing.Creator): AttributeError: module 'django.db.models.fields' 没有属性 'subclassing'
我不确定如何使用 HStoreField 并使用迁移创建扩展。这是我的文件结构。
webhook10/
|-- tutorial/
| |-- slack/
| | |-- migrations/
| | | +-- __init__.py
| | |-- __init__.py
| | |-- admin.py
| | |-- apps.py
| | |-- models.py
| | |-- tests.py
| | |-- urls.py
| | +-- views.py
| |-- tutorial/
| | |-- __init__.py
| | |-- settings.py
| | |-- urls.py
| | |-- wsgi.py
| +-- manage.py
+-- venv/
模型.py
from django.db import models
from django.utils import timezone
from django_hstore import hstore
class WebhookTransaction(models.Model):
UNPROCESSED = 1
PROCESSED = 2
ERROR = 3
STATUSES = (
(UNPROCESSED, 'Unprocessed'),
(PROCESSED, 'Processed'),
(ERROR, 'Error'),
)
date_generated = models.DateTimeField()
date_received = models.DateTimeField(default=timezone.now)
body = hstore.SerializedDictionaryField()
request_meta = hstore.SerializedDictionaryField()
status = models.CharField(max_length=250, choices=STATUSES, default=UNPROCESSED)
objects = hstore.HStoreManager()
def __unicode__(self):
return u'{0}'.format(self.date_event_generated)
class Message(models.Model):
date_processed = models.DateTimeField(default=timezone.now)
webhook_transaction = models.OneToOneField(WebhookTransaction)
team_id = models.CharField(max_length=250)
team_domain = models.CharField(max_length=250)
channel_id = models.CharField(max_length=250)
channel_name = models.CharField(max_length=250)
user_id = models.CharField(max_length=250)
user_name = models.CharField(max_length=250)
text = models.TextField()
trigger_word = models.CharField(max_length=250)
def __unicode__(self):
return u'{}'.format(self.user_name)
序列化程序.py
from rest_framework import serializers
from slack.models import WebhookTransaction, Message
class WebhookTransactionSerializer(serializers.ModelSerializer):
class Meta:
model = WebhookTransaction
fields = '_all_'
class MessageSerializer(serializers.ModelSerializer):
class Meta:
model = Message
fields = '_all_'
请告诉我可以做哪些改变?如果您想了解更多信息,请询问。