Hey, i am a little lost in a broken Format localization after manually setting a widget in formfield_overrides for an admin.TabularInline.
Before overriding the widget it looked like this:
Models:
# models.py
from decimal import Decimal
from django.db import models
class Ingredient(models.Model):
name = models.CharField(max_length=30)
def __str__(self):
return self.name
class Recipe(models.Model):
name = models.CharField(max_length=30)
ingredients = models.ManyToManyField(Ingredient, through='RecipeIngredients')
def __str__(self):
return self.name
class RecipeIngredients(models.Model):
recipe = models.ForeignKey(Recipe, on_delete=models.PROTECT)
orderpos = models.IntegerField()
amount_kg = models.DecimalField(max_digits=10, decimal_places=2,default=0)
ingredient = models.ForeignKey(Ingredient, on_delete=models.PROTECT)
note = models.CharField(max_length=30,default="",blank=True)
def __str__(self):
return "{} kg {} in {}".format(self.amount_kg,
self.ingredient,
self.recipe,
)
Admin:
# admin.py
from django.contrib import admin
from .models import Recipe
from .models import Ingredient
from .models import RecipeIngredients
class RecipeIngredientsInline(admin.TabularInline):
model = RecipeIngredients
show_change_link = False
extra = 0
fields = (
'orderpos',
'amount_kg',
'ingredient',
'note',
)
class RecipeAdmin(admin.ModelAdmin):
model = Recipe
inlines = [RecipeIngredientsInline,]
admin.site.register(Recipe,RecipeAdmin)
admin.site.register(Ingredient)
admin.site.register(RecipeIngredients)
Settings:
#settings.py DJANGO 3.2
LANGUAGE_CODE = 'en-US'
TIME_ZONE = 'Europe/Berlin'
USE_I18N = True
USE_L10N = True
USE_TZ = True
That results in a mix of german locale formats (“,” as decimal separator) in the editboxes and the english version (“.”) in some string representations. I do not understand that BUT it would be ok for me: