Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def get_fields(self, model):
fields = super(UserQLSchema, self).get_fields(model)
if model == User:
fields = [UserAgeField(), IntField(name='groups_count')] + fields
return fields
class BookQLSchema(DjangoQLSchema):
suggest_options = {
Book: ['genre'],
}
@admin.register(Book)
class BookAdmin(DjangoQLSearchMixin, admin.ModelAdmin):
djangoql_schema = BookQLSchema
list_display = ('name', 'author', 'genre', 'written', 'is_published')
list_filter = ('is_published',)
filter_horizontal = ('similar_books',)
class UserAgeField(IntField):
"""
Search by given number of full years
"""
model = User
name = 'age'
def get_lookup_name(self):
"""
We'll be doing comparisons vs. this model field
"""
return 'date_joined'
def get_lookup(self, path, operator, value):
if operator == 'in':
result = None
for year in value:
def get_field_cls(self, field):
str_fields = (models.CharField, models.TextField, models.UUIDField)
if isinstance(field, str_fields):
return StrField
elif isinstance(field, (models.AutoField, models.IntegerField)):
return IntField
elif isinstance(field, (models.BooleanField, models.NullBooleanField)):
return BoolField
elif isinstance(field, (models.DecimalField, models.FloatField)):
return FloatField
elif isinstance(field, models.DateTimeField):
return DateTimeField
elif isinstance(field, models.DateField):
return DateField
return DjangoQLField