There are two models connected to each other via OneToOne.

class Profile(models.model): user = models.OneToOneField(User, related_name = 'profile', null=True) class User(AbstractUser): #fields 

Each model is placed in the application (app) and has its own admin.py file.

For Profile admin.py looks like this

  class ProfileAdmin(admin.ModelAdmin): #prepopulated_fields = {"slug": ("profile.last_name",)} list_display = ('id', 'get_trainer_name', 'add_date', 'city', 'is_active', 'pause') inlines = [PortfolioImageInline, OrderInline, ] list_display_links = ['id', 'get_trainer_name'] save_on_top = True list_filter = ['is_active'] def get_trainer_name(self, obj): return obj.user.get_full_name() admin.site.register(Profile, ProfileAdmin) 

How can I display the fields of the User model in the admin panel on the Profile page and add prepopulated_fields (the line in the code)? The Inlines method works only for ForeignKey. Outputting the Profile fields in User works without problems, but vice versa. If at all possible in Django.

  • One-to-one relationships are normally displayed in forms via inline_model - Mr. Fix
  • @Mrfix Only on the side without OneToOne connection, no back. Maybe I'm wrong, then tell me where to look at the example. - Jekson

0