class MyUser(AbstractBaseUser):
...
content_type = models.ForeignKey(ContentType, limit_choices_to={"model__in": ("agentprofile", "clientprofile"))
object_id = models.PositiveIntegerField()
profile = generic.GenericForeignKey('content_type', 'object_id')
class AgentProfile(models.Model):
license_number = models.CharField(max_length=50, blank=True)
class ClientProfile(models.Model):
address = models.CHarField(max_length=250)
I have 3 models: MyUser(custom user model), ClientProfile, AgentProfile. How can I edit ClientProfile/AgentProfile on MyUser admin page (like inline)?
Basically it's a built in app that keeps track of models from the installed apps of your Django application. And one of the use cases of the ContentTypes is to create generic relationships between models.
The admin interface is also customizable in many ways. This post is going to focus on one such customization, something called inlines. When two Django models share a foreign key relation, inlines can be used to expose the related model on the parent model page. This can be extremely useful for many applications.
You need to use GenericTabularInline. See the Django docs.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With