Django admin, how to use model to add fields into another

226 Views Asked by At

I want to create a class that can be extended by users. I think in something similar to:

class User(model.Models):
    name = models.CharField(max_length=30)

class UserAttributes(model.Models):
    attribute_name = models.CharField(max_length=30)
    attribute_value = models.CharField(max_length=30)

What I want is to create an UserAttribute when I'm editing/creating an User.

1

There are 1 best solutions below

1
prince yadav On BEST ANSWER

You can use inlines model to show form in the admin.

class UserAttributeinline(admin.TabularInline)
    model = UserAttributes


@admin.register(User)
class UserAdmin(admin.ModelAdmin):
   inlines = [UserAttributesinline]