I have these models:
class App(models.Model): name = models.CharField(max_length=100) class ProjectA(models.Model): name = models.CharField(max_length=100) app = models.ForeignKey(App) class ProjectB(ProjectA): pass class Attachment(models.Model): content_type = models.ForeignKey(ContentType) object_id = models.PositiveIntegerField() project = generic.GenericForeignKey("content_type","object_id") file = models.FileField(upload_to=".")
I register all models for the administrator, and I do not register the group, user, and site. The fact is that when I get access to the attachment in the admin, I see that it looks like this:

In the Content Type field, select this list:

The reason for Attachment is GenericForeignKey, because both ProjectA and ProjectB must access it. I know that ProjectA and ProjectB are identical, but it is a requirement that they are stored in two separate tables. How could I make the Attachment class useful from the administrator? I know how to use contenttypes from regular views, but not from the administrator.
In the Attachment class, I would only like to select for Project A or Project B, and then a list of all Project A or all Project B, followed by the file I want to add.
Is this possible from the administrator? Do I need to show the object identifier column to the user?
django django-models django-admin django-contenttypes
Geo Jun 13 2018-11-11T00: 00Z
source share