Is it possible to use a form in the admin that is not associated with any model? Only to collect information that will already be used in a particular model. Detailed question with pictures below.

There is an abstract model of the CommonProperty object property, which depends on the Element object:

class Element(models.Model): class Meta: verbose_name = 'Element' verbose_name_plural = 'Elements' name = models.CharField(verbose_name="Name", max_length=255, blank=True, null=True) symbol = models.CharField(verbose_name="Symbol", max_length=255, blank=True, null=True) class CommonProperty(models.Model): class Meta: verbose_name = 'Property element' verbose_name_plural = 'Property elements' abstract = True TYPE = ( (THERMAL, 'thermal'), (PHYSICAL, 'physical'), (CLASSIFICATION, 'classification'), ) NOTATION = ( (DECIMAL, 'decimal'), (SCIENTIFIC, 'scientific'), (STRING, 'string'), ) element = ForeignKey(Element) title = models.CharField(verbose_name="Property title", max_length=255, blank=True, null=True) type = models.CharField(verbose_name="Property type", max_length=50, choices=TYPE) notation = models.CharField(verbose_name="Property notation", max_length=50, choices=NOTATION) 

CommonProperty contains a type selection (how the value of this property will be written - a decimal number, an engineering record, or just a string). Depending on the type chosen, the corresponding model is used - inheritor CommonProperty

 class PropertyDecimalNotation(CommonProperty): class Meta: verbose_name = 'Decimal Notation' value = models.FloatField(verbose_name="Value", blank=True, null=True) unit = models.CharField(verbose_name="Unit", max_length=255, blank=True, null=True) class PropertyScientificNotation(CommonProperty): class Meta: verbose_name = 'Scientific Notation' significand = models.FloatField(verbose_name="Significand", blank=True, null=True) base = models.IntegerField(verbose_name="Base", blank=True, null=True) exponent = models.IntegerField(verbose_name="Exponent", blank=True, null=True) unit = models.CharField(verbose_name="Unit", max_length=255, blank=True, null=True) class PropertyStringNotation(CommonProperty): class Meta: verbose_name = 'Property string notatio' value = models.CharField(verbose_name="Value", max_length=255, blank=True, null=True) unit = models.CharField(verbose_name="Unit", max_length=255, blank=True, null=True) 

And actually the question

Is it possible to organize the following logic in admin panel?

  1. Initially, in the admin there is a form for selecting the type and form of the property record. Where we can specify the title of the future property, select the group and the recording format. This is an intermediate form for the abstract CommonProperty model.

enter image description here

  1. Depending on the choice of the recording format (decimal, engineering view or string), after saving the object (or clicking the Add property button) we get a new form, where we fill in the element properties in detail

    In the figure, I chose the number engineering format as an example.

enter image description here

Is it possible to organize the form on the fields of an abstract model? And already the data of this form to use when creating the necessary records in the database? please give advice

    1 answer 1

    It is impossible to work with your forms using the standard django admin tools. An admin is a high-level interface for working with a database.

    But you can saw through the admin itself, if your task did not get into 90% of the solved. Although this is not a trivial task. There is, for example, the ability to override templates.

    In fact, as I understand your level, it will be much easier to make a separate page with the desired form, without touching the administrative interface.

    • Yes, I was already thinking about a separate add page. you are right about the level, I can do simple customization and template substitution, but this task caused me great difficulty - while1pass
    • Thanks for the likes, but it makes no sense to throw them in such quantities, since the system still removes the "jerks". at the end of the day. - Mr. Fix
    • I'll know. it is necessary to somehow encourage interest. but I can dislike) - while1pass