jet-admin / jet-django

Jet Bridge (Django) for Jet Admin – Admin panel framework for your application

Home Page:https://app.jetadmin.io/demo

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

[Bug] Fields internationalization - Useless field shown + values not displayed

Vadorequest opened this issue · comments

I use django-modeltranslation to add fields internationalization in my models.

I basically configure the following in my models.py:

label = models.CharField(
    help_text="Displayed label",
    max_length=100,
    null=False,
    blank=False,
  )

And end up with the following fields:
label, label_fr, label_en

Jet doesn't seem to understand it very well:
image

It doesn't make much sense to display the generic label field, it's counter-intuitive in such case at best. Here is the field configuration:
image

There is no way to "hide" the field so it cannot be shown at all by default.


Also, and much more of an issue for me, the internationalized fields don't show:

image

But I do have the proper data in the DB:
image

The reason behind the bug seems to be from the API itself, the API doesn't seem to know about the localized fields and only returns the main one. Maybe should I change configure something differently there?
image

@Vadorequest regarding hiding field, its possible with visual editor as described here:
https://docs.jetadmin.io/manipulate/summary-view

regarding values not shown, i need to investigate it more detailed, which data type is specified for them in JET btw?

The values (label_fr, label_en) are not shown, because my model doesn't explicitly list them.

Here is my Model:

from django.contrib.contenttypes.fields import GenericRelation
from django.db import models
from jsonfield import JSONField


class Org(models.Model):
  name = models.SlugField(
    help_text="Name which references the organisation (unique)",
    max_length=50,
    unique=True,
  )
  label = models.CharField(
    help_text="Displayed label",
    max_length=100,
    null=False,
    blank=False,
  )
  logo = JSONField(
    help_text="Logo (JSON). All fields are required<br />"
              "Structure is likely to evolve and therefore stored as JSON for the sake of simplicity",
    default='',
    null=False,
    blank=False,
  )
  apps = JSONField(
    help_text="Applications configuration (JSON)<br />"
              "Structure is likely to evolve and therefore stored as JSON for the sake of simplicity",
    default='',
    null=False,
    blank=False,
  )
  # Reverse generic relation - XXX See https://docs.djangoproject.com/en/dev/ref/contrib/contenttypes/#reverse-generic-relations
  student_solutions = GenericRelation('student_solution.StudentSolution')

  class Meta:
    # https://docs.djangoproject.com/en/2.1/ref/models/options/#django.db.models.Options.db_table
    db_table = "tfp_organisations"
    verbose_name = 'Organisation'
    verbose_name_plural = 'Organisations'

    # https://docs.djangoproject.com/en/2.1/ref/models/options/#indexes
    # indexes = [
    #   models.Index(fields=['name', 'name']),
    # ]

  def __str__(self):
    return self.label

As you can see, there is no mention of label_en or label_fr, it's because those fields are added in the model at runtime. But they exist in the DB.

from modeltranslation.translator import translator, TranslationOptions

from tfp_backoffice.apps.org.models import Org


class OrgTranslationOptions(TranslationOptions):
  """
  See https://django-modeltranslation.readthedocs.io/en/latest/registration.html
  """
  fields = ('label',)
  required_languages = ('fr',)  # ex: {'de': ('title', 'text'), 'default': ('title',)}


translator.register(Org, OrgTranslationOptions)

It's a particular edge case, JET maps the model but is not aware of those fields that are added a bit differently, through a register

@Vadorequest hello!

managed to investigate this issue: the problem is that django-modeltranslation patches django models so you need to run jet_django only after django-modeltranslation has finished its patching like this in your settings.py:

INSTALLED_APPS = (
...
'modeltranslation',
'jet_django', # after modeltranslation

)