Company logo
  • Jobs
  • Bootcamp
  • About Us
  • For professionals
    • Home
    • Jobs
    • Courses
    • Questions
    • Teachers
    • Bootcamp
  • For business
    • Home
    • Our process
    • Plans
    • Assessments
    • Payroll
    • Blog
    • Sales
    • Calculator

0

104
Views
OneToOneField in Django admin not editable

I've stripped my code all the way down and am left with these simple models:

models.py

class Member(models.Model):
    property = models.OneToOneField(Property, on_delete=models.CASCADE, blank=True, null=True)

class Property(models.Model):
    ....

And this very basic admin for Members:

admin.py

class PropertyAdmin(admin.ModelAdmin):
   pass
admin.site.register(Property, PropertyAdmin)

class MemberAdmin(admin.ModelAdmin):
    pass
admin.site.register(Member, MemberAdmin)

While logged into the admin as a superuser, as expected on the Member admin page I see a dropdown to choose a Property model. When there is already a Property model selected, the usual pencil icon to edit the selected Property model is faded out, so I cannot click on it. How can I activate this icon so that I can get the usual pop-up to edit the related Property from this Member page? I can't figure out what I am missing.

Thank you!

8 months ago · Santiago Trujillo
2 answers
Answer question

0

You're not registering the Property model in admin.

@admin.site.register(Property)
class PropertyAdmin(admin.ModelAdmin):
    pass
8 months ago · Santiago Trujillo Report

0

Agreed with @Andrey Shipilov,

You can follow in this way also.

class PropertyAdmin(admin.ModelAdmin):
    pass
admin.site.register(Property, PropertyAdmin)
8 months ago · Santiago Trujillo Report
Answer question
Find remote jobs