Feature(s) impacted
SmartFields not showing up for the Django integration.
Observed behavior
I tried the Django code sample from the official documentation:
Unfortunately, I have not been able to create a single SmartField no matter how badly I try. Here is a code sample:
import uuid
from django.db import models
from django_forest.utils.collection import Collection
class Address(models.Model):
id = models.UUIDField(default=uuid.uuid4, primary_key=True)
contact_name = models.CharField(max_length=256, blank=True)
contact_last_name = models.CharField(max_length=256, blank=True)
class AddressForest(Collection):
def load(self):
self.name = "account_address"
self.fields = [
{
'field': 'full_contact_name',
'type': 'String',
'get': self.get_fullname
},
]
def get_fullname(self, obj):
print("Trying to get FullName for address...")
return "%s %s" % (obj.contact_name, obj.contact_last_name)
Collection.register(AddressForest, Address)
I tried doing everything, moving the AddressForest
class to a different file, I tried putting it into the main
project directory, I tried checking if there is a Forest setting that I need to review but nothing works.
Also, I tried the self.name
property inside the load
function and outside of it without luck. I also tried the account_address
name without success as well as Address
, and address
without new results. Whenever I try to edit the layout in the Forest Admin UI I check for hidden fields without success. I checked the schema file but the SmartField is never registered.
{
"name": "account_address",
"is_virtual": false,
"icon": null,
"is_read_only": false,
"is_searchable": true,
"only_for_relationships": false,
"pagination_type": "page",
"search_fields": null,
"actions": [],
"segments": [],
"fields": [
{
"field": "id",
"type": "String",
"is_filterable": true,
"is_sortable": true,
"is_read_only": false,
"is_required": false,
"is_virtual": false,
"default_value": null,
"integration": null,
"reference": null,
"inverse_of": null,
"relationship": null,
"widget": null
},
{
"field": "contact_name",
"type": "String",
"is_filterable": true,
"is_sortable": true,
"is_read_only": false,
"is_required": false,
"is_virtual": false,
"default_value": null,
"integration": null,
"reference": null,
"inverse_of": null,
"relationship": null,
"widget": null,
"validations": [
{
"type": "is shorter than",
"message": "Ensure this value has at most 256 characters",
"value": 256
},
{
"type": "is present",
"message": "Ensure this value is not null or not empty"
}
]
},
{
"field": "contact_last_name",
"type": "String",
"is_filterable": true,
"is_sortable": true,
"is_read_only": false,
"is_required": false,
"is_virtual": false,
"default_value": null,
"integration": null,
"reference": null,
"inverse_of": null,
"relationship": null,
"widget": null,
"validations": [
{
"type": "is shorter than",
"message": "Ensure this value has at most 256 characters",
"value": 256
},
{
"type": "is present",
"message": "Ensure this value is not null or not empty"
}
]
},
]
},
Expected behavior
I expected to see the SmartField somewhere and no luck so far. I tried looking for an example on the Github repositories for Django but no luck. All I need to find is a very good example of a SmartField since I’m blocked on my progress due to a massive table where adding a new field would slow the performance and imply massive downtime.
Failure Logs
No failure logs were reported, BUT I did write a print statement when joining the two string fields and never got it to show up anywhere on the logs.
Context
- Project name: Kiara Dashboard
- Team name: Operations
- Environment name: Development
- Agent type & version: Django 1.4.4 Python 3.10.9
- Recent changes made on your end if any: Nope