Как установить lookup_field GenericViewSet с ключом JSONfield?
Как установить lookup_field с ключом в модели JSONField?
Модель:
exchange = models.ForeignKey(StockExchange, on_delete=models.CASCADE, related_name='tickers')
fundamentals = models.JSONField(null=True, blank=True)
Набор представлений:
class StockCardsV2ViewSet(BaseGetViewSet):
search_fields = ('^fundamentals__General__Name', '^fundamentals__General__Code')
filter_backends = (filters.SearchFilter,)
queryset = Ticker.objects.all()
serializer_class = StockCardsV2Serializer
lookup_value_regex = '[0-9a-zA-Z_.]+'
lookup_field = 'fundamentals__General__Code'
Сериализатор:
class Meta:
model = Ticker
fields = ('id', 'url', 'name', 'ticker', 'logo_url', 'currency_symbol', 'sector', 'industry', 'esg_rating',
'weekly_prices', 'monthly_prices', 'yearly_prices', 'two_yearly_prices', 'ad', 'in_watchlist')
lookup_field = 'fundamentals__General__Code'
extra_kwargs = {
'url': {'lookup_field': 'fundamentals__General__Code'},
}
С полями поиска проблем нет, но я получаю эту ошибку для поля поиска.
'Ticker' object has no attribute 'fundamentals__General__Code'
Фундаментальные основы:
"fundamentals": {
"General": {
"CIK": null,
"LEI": null,
"Code": "SATX-WTA",
"ISIN": null,
"Name": "Satixfy Communications Ltd.",
}
},