You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I have extended django user model by adding it as foreign key in UserProfile Model. And I want to my User Admin to have all the fields of usermodels along with the fields of UserProfile.
Lucky which was working perfectly until i turn my UserProfile Model Translatable using django HVAD.
I am sharing my model along with admin code. Any suggestion to counter this issue is welcomed using django Hvad
class UserProfile(TranslatableModel):
translations = CustomTranslatedFields(
first_name=models.CharField(_('first name'), max_length=30, blank=True),
last_name=models.CharField(_('last name'), max_length=30, blank=True),
bio=models.TextField(
verbose_name=_('Biography'),
blank=True
),
translation_created=models.DateTimeField(
verbose_name=_('Creation date'),
auto_now_add=True,
editable=False,
),
translation_created_by=models.ForeignKey(
User,
related_name="%(app_label)s_%(class)s_created_by",
editable=False,
),
translation_updated=models.DateTimeField(
verbose_name=_('Update date'),
auto_now=True,
editable=False,
),
translation_updated_by=models.ForeignKey(
User,
related_name="%(app_label)s_%(class)s_updated_by",
null=True,
blank=True,
),
)
user = models.OneToOneField(
User,
related_name='user_profile',
verbose_name=_('User Profile'),
)
job_title = models.ForeignKey(
Jobtitle,
db_column='job_title',
verbose_name=_('Job Title'),
)
company = models.ForeignKey(
Company,
db_column='company',
verbose_name=_('company'),
help_text=_("The company you were or are working at. If your entered company does not exist in the autocomplete dropdown, simply type it in and it will be added to the library automatically."),
)
class CustomUserAdmin(TranslatableAdmin, UserAdmin):
actions = None
form = UserCustomChangeForm
add_form = UserCustomCreationForm
inlines = [
UserProfileInline,
UserPointsInline,
UserExperienceInline,
UserEducationInline,
UserWebsitesInline,
RelationshipInline,
]
admin.site.unregister(User)
admin.site.register(User, CustomUserAdmin)
The text was updated successfully, but these errors were encountered:
Hello,
Thanks for reporting here. Could you please describe the issue you have? The admin component is the one I am less familiar with in the codebase as it was written before I joined the project, so your problem is not obvious to me.
Do you have errors? Unexpected behavior?
Oh, alright. Well, TranslationAdmin only works on translatable models, so it won't work with User.
That means you cannot inline a translatable model in a non-translatable admin form, unfortunately that's not supported. The issue is it would be inherently ambiguous which translations are to be used, since the main object does not have a language.
I would suggest one of the following approaches:
Use your UserProfile model instead as main editing point. This might be troublesome though as Django's admin does not support nested inlines.
Implement a custom admin subclass that knows about loading the correct translations based on your project's rules.
I have extended django user model by adding it as foreign key in UserProfile Model. And I want to my User Admin to have all the fields of usermodels along with the fields of UserProfile.
Lucky which was working perfectly until i turn my UserProfile Model Translatable using django HVAD.
I am sharing my model along with admin code. Any suggestion to counter this issue is welcomed using django Hvad
The text was updated successfully, but these errors were encountered: