У меня проблема с тем, что я больше не уверен, что делаю что-то не так или что-то не так с пакетом.
У меня есть заказной фильтр заказа django - фильтр:
class CustomOrderingFilter(OrderingFilter):
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
self.extra['choices'] += [
('trainingDates', 'Training Dates'),
('-trainingDates', 'Training Dates (descending)'),
]
def filter(self, qs, value):
if any(v in ['trainingDates', '-trainingDates'] for v in value):
data = qs.annotate(first_date=Min('training_dates__date')).order_by('first_date')
return data
return super().filter(qs, value)
Когда я добавляю точку отладки, добавляю инструкцию возврата, я вижу поле 'first_date', но когда я продолжаю, я получаю следующую ошибку:
ERROR 2020-02-20 14:00:45,047 utils 24233 Traceback (most recent call last):
File "/home/bart/projects/coursemanager/backend/venv/lib/python3.7/site-packages/promise/promise.py", line 487, in _resolve_from_executor
executor(resolve, reject)
File "/home/bart/projects/coursemanager/backend/venv/lib/python3.7/site-packages/promise/promise.py", line 754, in executor
return resolve(f(*args, **kwargs))
File "/home/bart/projects/coursemanager/backend/venv/lib/python3.7/site-packages/graphql/execution/middleware.py", line 75, in make_it_promise
return next(*args, **kwargs)
File "/home/bart/projects/coursemanager/backend/venv/lib/python3.7/site-packages/graphene_django/filter/fields.py", line 107, in connection_resolver
**args
File "/home/bart/projects/coursemanager/backend/venv/lib/python3.7/site-packages/graphene_django/fields.py", line 164, in connection_resolver
return on_resolve(iterable)
File "/home/bart/projects/coursemanager/backend/venv/lib/python3.7/site-packages/graphene_django/fields.py", line 118, in resolve_connection
pageinfo_type=PageInfo,
File "/home/bart/projects/coursemanager/backend/venv/lib/python3.7/site-packages/graphql_relay/connection/arrayconnection.py", line 88, in connection_from_list_slice
for i, node in enumerate(_slice)
File "/home/bart/projects/coursemanager/backend/venv/lib/python3.7/site-packages/django/db/models/query.py", line 274, in __iter__
self._fetch_all()
File "/home/bart/projects/coursemanager/backend/venv/lib/python3.7/site-packages/django/db/models/query.py", line 1242, in _fetch_all
self._result_cache = list(self._iterable_class(self))
File "/home/bart/projects/coursemanager/backend/venv/lib/python3.7/site-packages/django/db/models/query.py", line 55, in __iter__
results = compiler.execute_sql(chunked_fetch=self.chunked_fetch, chunk_size=self.chunk_size)
File "/home/bart/projects/coursemanager/backend/venv/lib/python3.7/site-packages/django/db/models/sql/compiler.py", line 1087, in execute_sql
sql, params = self.as_sql()
File "/home/bart/projects/coursemanager/backend/venv/lib/python3.7/site-packages/django/db/models/sql/compiler.py", line 474, in as_sql
extra_select, order_by, group_by = self.pre_sql_setup()
File "/home/bart/projects/coursemanager/backend/venv/lib/python3.7/site-packages/django/db/models/sql/compiler.py", line 55, in pre_sql_setup
order_by = self.get_order_by()
File "/home/bart/projects/coursemanager/backend/venv/lib/python3.7/site-packages/django/db/models/sql/compiler.py", line 330, in get_order_by
field, self.query.get_meta(), default_order=asc))
File "/home/bart/projects/coursemanager/backend/venv/lib/python3.7/site-packages/django/db/models/sql/compiler.py", line 704, in find_ordering_name
field, targets, alias, joins, path, opts, transform_function = self._setup_joins(pieces, opts, alias)
File "/home/bart/projects/coursemanager/backend/venv/lib/python3.7/site-packages/django/db/models/sql/compiler.py", line 734, in _setup_joins
field, targets, opts, joins, path, transform_function = self.query.setup_joins(pieces, opts, alias)
File "/home/bart/projects/coursemanager/backend/venv/lib/python3.7/site-packages/django/db/models/sql/query.py", line 1504, in setup_joins
names[:pivot], opts, allow_many, fail_on_missing=True,
File "/home/bart/projects/coursemanager/backend/venv/lib/python3.7/site-packages/django/db/models/sql/query.py", line 1420, in names_to_path
"Choices are: %s" % (name, ", ".join(available)))
graphql.error.located_error.GraphQLLocatedError: Cannot resolve keyword 'first_date' into field. Choices are: amount, comment, company, confirmed, course_name, deleted, email, first_name, function, id, invoice, last_name, phone_number, present, reminder, training_dates, unregistered_dates
Кто-нибудь знаете как это исправить? То, что я хочу, это заказать к первому свиданию в отношении многих ко многим. Если вы хотите увидеть больше кода, дайте мне знать.
Редактировать # 1: Регистрация модели
class RegistrationManager(models.QuerySet):
def active(self):
return self.filter(deleted__isnull=True)
class Registration(models.Model):
first_name = models.CharField(max_length=64)
last_name = models.CharField(max_length=64)
email = models.EmailField()
phone_number = models.CharField(max_length=64, blank=True, null=True)
amount = models.PositiveIntegerField(blank=True, null=True)
invoice = models.BooleanField()
company = models.CharField(max_length=64)
function = models.CharField(max_length=64, blank=True, null=True)
confirmed = models.BooleanField()
reminder = models.BooleanField()
present = models.BooleanField()
training_dates = models.ManyToManyField('training.TrainingDate', related_name='registrations')
unregistered_dates = models.ManyToManyField('training.TrainingDate', related_name='unregistered_registrations',
blank=True)
course_name = models.CharField(max_length=64, null=True, blank=True)
comment = models.CharField(max_length=512, blank=True, null=True)
deleted = models.DateTimeField(null=True, blank=True)
objects = RegistrationManager.as_manager()
def delete(self):
self.deleted = datetime.now()
self.save()
def __str__(self):
return "{} {} ({})".format(self.first_name, self.last_name, self.company)